Results 1 to 8 of 8
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Dimond not working

    Java Code:
    interface OrderedPairI<K, V> {
    	K getKey();
    
    	V getValue();
    }
    
    class Generics<K, V> implements OrderedPairI<K, V> {
    
    	private K key;
    	private V value;
    
    	public Generics(K key, V value) {
    		this.key = key;
    		this.value = value;
    	}
    
    	@Override
    	public K getKey() {
    		return key;
    	}
    
    	@Override
    	public V getValue() {
    		return value;
    	}
    
    	public static void main(String[] args) {
    
    		Generics<String, Integer> o = new Generics<>("Allaudin", 13); // Error
     // Incorrect number of arguments for type Generics<K,V>; it cannot be parameterized with arguments <?>
    		System.out.println(o.getKey() + " " + o.getValue());
    		
    	}
    }
    
    According to java tutorials it should work but it doesn't ... it works fine with 
    Generics<String, Integer> o = new Generics<String, Integer>("Allaudin", 13);
    Last edited by allaudin; 06-24-2013 at 04:55 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Dimond not working

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Dimond not working

    Quote Originally Posted by allaudin View Post
    Generics<String, Integer> o = new Generics<>("Allaudin", 13); // Error
    // Incorrect number of arguments for type Generics<K,V>; it cannot be parameterized with arguments <?>

    According to java tutorials it should work but it doesn't ... it works fine with Generics<String, Integer> o = new Generics<K, V>("Allaudin", 13);
    Make that:
    Java Code:
    		Generics<String, Integer> o = new Generics<String, Integer>("Allaudin", 13);
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Dimond not working

    Which Java version? The diamond operator <> was introduced in Java 7.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Dimond not working

    yea I have installed jre7 but my eclipse sticks to 1.6 .. I have changed it to default jre7 but still showing error . In execution environment of eclipse I have JavaSE-1.6(jre7) or less... I copied this code from Generic Types (The Java™ Tutorials > Learning the Java Language > Generics (Updated))
    Last edited by allaudin; 06-24-2013 at 04:49 PM.

  6. #6
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Dimond not working

    josAH I know its working for
    Java Code:
    Generics<String, Integer> o = new Generics<String, Integer>("Allaudin", 13);

  7. #7
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Dimond not working

    ;) Now I know the problem is with my Eclipse :/

  8. #8
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Dimond not working

    Thanks friends ... I have installed new eclipse version it works now

Similar Threads

  1. Not working!
    By verde in forum New To Java
    Replies: 13
    Last Post: 04-15-2012, 03:47 PM
  2. Collisions are working & not working
    By Jayayoh in forum Java 2D
    Replies: 1
    Last Post: 06-24-2011, 05:21 PM
  3. if else not working
    By silverglade in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 07:29 PM
  4. Replies: 2
    Last Post: 01-04-2011, 04:30 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Posting Permissions

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