• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quick Java Question..

SnoopCat

Senior member
Are templates legal in Java?
For example:

private List<Book> bookList;


I have seen this done in C/C++ but not in Java. (im more of a c/c++ than Java person)

Im having a tough time trying to get my compiler to accept it.

any comments?
 
Yeah it's a very recent addition to Java, so unless you're compiling with the 1.5 compiler, it won't accept it.

--Mark
 
Can someone explain to me what the point of templates in Java are? Since everything inherits from Object anyway, why template a list? Is it only to enforce the type?
 
Originally posted by: KingNothing
Can someone explain to me what the point of templates in Java are? Since everything inherits from Object anyway, why template a list? Is it only to enforce the type?

When you get something out of the list, it's always a reference of the type you specified inside the <>.

Also handy for the new for each loop like:

ArrayList<Building> stuff = new ArrayList<Building>();
// put stuff in it
for(Building b : stuff)
{
System.out.println(b.getCost());
}

 
Back
Top