Results 1 to 4 of 4
Thread: Java confused over Generics?
- 12-26-2007, 12:07 AM #1
Member
- Join Date
- Oct 2007
- Posts
- 7
- Rep Power
- 0
Java confused over Generics?
I have just installed java on a new computer, and it doesn't seem to recognise the syntax for Generic classes and methods.
I copied some code from my old computer over and it runs fine - but when I try to compile code (even with no changes) I get errors that I didn't get before.
Here's the full code, though I doubt there's any problems with it. It compiled on my other computer.Java Code:ConnectionPoint.java:7: <identifier> expected private ArrayList<Line> connectionLines; ^ ConnectionPoint.java:11: '(' or '[' expected connectionLines=new ArrayList<Line>(); ^ ConnectionPoint.java:14: <identifier> expected public void assignConnections(ArrayList<Line> cL){connectionLines=cL ^ ConnectionPoint.java:54: ')' expected } ^
I've installed all the necessary components of java (the SDK, J2RE, and JDK) without a problem. Please help!Java Code:package SimpleGeometry; import java.util.*; import SimpleGeometry.*; public class ConnectionPoint extends EPoint{ private ArrayList<Line> connectionLines; public ConnectionPoint(int x, int y){ super(x,y); connectionLines=new ArrayList<Line>(); } public void assignConnections(ArrayList<Line> cL){connectionLines=cL;} public void removeConnection(Line l){connectionLines.remove(l);} public void addConnection(Line l){connectionLines.add(l);} public void tryConnection(Line l){ if(isConnectedTo(l)){ addConnection(l); } } public boolean isConnectedTo(Line l){ EPoint p1=l.getP1(); EPoint p2=l.getP2(); if(equals(p1)||equals(p2)){ return true; } return false; } public ArrayList<Line> getConnections(){ return connectionLines; } public String toCString(){ Line l; String s=""; Iterator<Line> iter = connectionLines.iterator(); while(iter.hasNext()){ l=(Line)iter.next(); s+= l.toString(); s+="\n"; } return s; } }
- 12-26-2007, 04:15 AM #2
It might be possible that an earlier version of java or the jre (came pre-installed and) is being used by your computer. Check with:
Java Code:C:\jexp>java -version java version "1.6.0_03" Java(TM) SE Runtime Environment (build 1.6.0_03-b05) Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
- 12-26-2007, 06:01 AM #3
Member
- Join Date
- Oct 2007
- Posts
- 7
- Rep Power
- 0
That's exactly the same version number I have. :/
- 12-26-2007, 06:23 AM #4
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
are you compiling the code from command prompt or using an IDE? please make sure the JDK use in IDE support the Generic feature of Java.
Website: Learn Java by Examples
Similar Threads
-
The words *game* in java programming :confused:
By ibmzz in forum Advanced JavaReplies: 1Last Post: 01-23-2008, 09:23 AM -
Generics
By sireesha in forum New To JavaReplies: 2Last Post: 01-10-2008, 11:08 PM -
Java Generics (an introduction)
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 11-27-2007, 06:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks