Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Generics problem

    Java Code:
    abstract class ABS<K extends Number>
    {
    	public abstract <K> K useMe(Object k);// understood ..  
    	public abstract <K> ABS<? extends Number> useMe(ABS<? super K> k)	; //1
    	public abstract <K> ABS<? super Number> useMe(ABS<? extends K> k); //2
    	public abstract <K> ABS<K> useMe(ABS<K> k);// understood ..  
    }
    1 and 2 this both should not work because K can be anything here....

    can anyone please explain???

    Thanks in advance....

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

  3. #3
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Hi.
    You have methods this a same name useMe.
    I changed your code as follows
    Java Code:
    public abstract class ABS<K extends Number> {
    	public abstract <K> K useMe(Object k);
    
        public abstract <K extends Number> ABS<? extends Number> useMeExtends(ABS<? super K> k);
    
    	public abstract <K> ABS<? super Number> useMeSuper(ABS<? extends K> k);
    
    	public abstract <K extends Number> ABS<K> useMe(ABS<K> k);
    }
    Skype: petrarsentev
    http://TrackStudio.com

Similar Threads

  1. Help with generics
    By shai in forum New To Java
    Replies: 0
    Last Post: 08-12-2010, 07:07 AM
  2. generics
    By tascoa in forum Forum Lobby
    Replies: 2
    Last Post: 10-09-2008, 07:58 PM
  3. Help w/ generics
    By Hollywood in forum New To Java
    Replies: 2
    Last Post: 02-16-2008, 03:08 AM
  4. Generics
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 01-10-2008, 11:08 PM
  5. Generics
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-04-2008, 09:10 PM

Tags for this Thread

Posting Permissions

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