Results 1 to 4 of 4
  1. #1
    Bibendum is offline Member
    Join Date
    Oct 2007
    Posts
    7
    Rep Power
    0

    Default 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.

    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
    }
    ^
    Here's the full code, though I doubt there's any problems with it. It compiled on my other computer.

    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;
    	}
    }
    I've installed all the necessary components of java (the SDK, J2RE, and JDK) without a problem. Please help!

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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)

  3. #3
    Bibendum is offline Member
    Join Date
    Oct 2007
    Posts
    7
    Rep Power
    0

    Default

    That's exactly the same version number I have. :/

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    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.

Similar Threads

  1. The words *game* in java programming :confused:
    By ibmzz in forum Advanced Java
    Replies: 1
    Last Post: 01-23-2008, 09:23 AM
  2. Generics
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 01-10-2008, 11:08 PM
  3. Java Generics (an introduction)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 11-27-2007, 06:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •