Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

incompatible types error 1

Status
Not open for further replies.

sangrg

Technical User
Oct 25, 2006
4
US
Below, what's the best way to fix
incompatible types error in method getSize() ?

Thanks.


import java.util.*;
import java.lang.*;
import java.io.*;
/**
*
* @author Administrator
*/
public class FacultyList {

/** Creates a new instance of StudentList */
private List facultys = new LinkedList();
private static FacultyList facultyList;

private FacultyList() {
}
public static FacultyList instance() {
if (facultyList == null) {
return (facultyList = new FacultyList());
} else {
return facultyList;
}
}


public boolean addFaculty(Faculty faculty){
facultys.add(faculty);
return true;
}

public Iterator getFacultys(){
return facultys.iterator();
}

public String toString(){
return facultys.toString();
}

public Faculty Search(String facultyID){
for (Iterator iterator = facultys.iterator(); iterator.hasNext();){
Faculty faculty = (Faculty) iterator.next();
if (faculty.getFacultyID().equals(facultyID)){
return faculty;
}
} return null;
}

public Integer getSize(){
return facultys.size();
//return (Integer) facultys.size(); do not work
}
}

 
You cannot cast a primitive data type to an object.

So either :

public int getSize() {
return facultys.size();
}

or

public Integer getSize() {
return new Integer(facultys.size());
}

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top