Generics Problem

I have a coding requirement that I would like to solve using generics, though I can't seem to get past an issue. My real example is way too complicated to post all of it here, but I'll try to simplify as much as possible (meaning, let's not get caught up in all the error checking, etc).
I have an interface:
public interface Function<T> {
     public void doSomething(T value);
}Then, I have a class:
public class LengthFunction implements Function<String> {
     private int length;
     public void doSomething(String value) {
          this.length += value.length();
     public int getLength() { return this.length; }
}And, another class:
public class CountFunction<T> implements Function<T> {
    private int count;
    public void doSomething(T value) {
        count++;
    public int getCount() { return this.count; }
}Then, I have the workhorse:
public class WorkHorse<C, T> {
    private HashMap<String, Function<T>> map;
    private Collection<C> list;
    public WorkHorse(Collection<C> incoming) {
        this.map = new HashMap<String, Function<T>>();
        this.list = new ArrayList<C>(incoming);
   public void addFunction(String key, Function<T> function) {
       this.map.put(key, function);
   public void process() {
        for (C element : this.list) {
             for (String key : this.map.keySet()) {
               for (Function<T> function : this.map.get(key)) {
                       T value = (T)magicalThingToGetValueFromElementOfTypeT(element, key);  // returns object
                    function.doSomething(value);
}And finally, a process somewhere (let's play it this way):
public void Process {
    public static void main(String[] args) {
         ArrayList<String> strings = new ArrayList<String>();
         // Fill array list with strings
         WorkHorse<String, Object> wh = new WorkHorse<String, Object>(strings);
         LengthFunction lf = new LengthFunction();
         CountFunction<Double> cf = new CountFunction<Double>();
         wh.addFunction("length", lf); // Compiler Error Here
         wh.addFunction("count", cf); // Compiler Error Here
         wh.process();
         System.out.println("Length: " + lf.getLength());
         System.out.println("Count: " + cf.getCount());       
}The two places where it complains are noted, and it is complaining with:
The method addFunction(String, Function<Object>) in the type WorkHorse<String,Object> is not applicable for the arguments (String, LengthFunction<String>)and
The method addFunction(String, Function<Object>) in the type WorkHorse<String,Object> is not applicable for the arguments (String, CountFunction<Double>)So, I'm missing something... and I appear to be too stupid to figure it out.
Any help is appreciated.
Joe

I haven't seen the "? super C" syntax. How is that different from "? extends C"?
Since the function argument type will be the same as the collection contents type, there's no reason for having two type parameters on WorkhorseThere is. The first parameter on WorkHorse is the type of the elements in the collection. The second is the type of a value a given function is designed to work against. That value is obtained by invoking a method on each element in the list and then provided to the function. That is pretty complicatated, and relatively unimportant for this problem, so I elided with:
T value = (T)magicalThingToGetValueFromElementOfTypeT(element, key);  // returns objectSo, therefore, if given an element of type MathThing in the WorkHorse, and that type has a method that returns a Double, then we'd want WorkHorse<MathThing, Double>. Likewise, if we have an element of type ColorThing, and it has a method that returns a Color, we'd want WorkHorse<ColorThing, Color>. Then, we'd have something like AFunction<Double> and BFunction<Color>.
I was interested, though, and made a quick change to the WorkHorse class... and I'm still getting fundamentally the same error:
The method addFunction(String, Function<? super Object>) in the type WorkHorse<String,Object> is not applicable for the arguments (String, Function<String>)When I instantiate WorkHorse with <String, Object>. Again, if I do WorkHorse<String, String> and use only implementations equivalent to Function<String>, I'm OK. However, if I do WorkHorse<String, Object> and have two Function<Strings> and one Function<Double>, I have the problem.

Similar Messages

  • Generics problem - unchecked and unsafe problems

    basically my teacher said it needs to run if she types in "% javac *.java " otherwise i'll get a zero...
    so with that said, i've read that to fix the generic problem you can do the -Xlint:unchecked but that wont help me.
    and i've also read about raw types being the source of the problem, but now i'm completely stuck as to how to fix it. any suggestions would be greatly appreciated.
    here is my source code for the file that is causing this:
    import java.io.*;
    import java.util.*;
    public class OrderedLinkedList<T> implements OrderedListADT<T>
         private int size;
         private DoubleNode<T> current;
         public OrderedLinkedList()
              size = 0;
              current = null;
         public void add (T element)
              boolean notBegin = true;
              size = size + 1;
              if (isEmpty())
                   current = new DoubleNode<T>(element);
              while (current.getPrevious() != null)
                   current = current.getPrevious();
              Comparable<T> cElement = (Comparable<T>)element;
              while (cElement.compareTo(current.getElement()) > 0)
                   if (current.getNext() != null)
                        current = current.getNext();
                   else
                        notBegin = false;
              if (notBegin)
                   DoubleNode<T> temp = new DoubleNode<T>(element);
                   DoubleNode<T> temp2 = current;
                   current.setPrevious(temp);
                   temp.setNext(current);
                   temp.setPrevious(temp2.getPrevious());
                   current = temp;
              else
                   DoubleNode<T> temp = new DoubleNode<T>(element);
                   while (current.getPrevious() != null)
                        current = current.getPrevious();
                   temp.setNext(current);
                   current.setPrevious(temp);
         public T removeFirst()
              try
                   if (isEmpty())
                        throw new EmptyCollectionException("List");
              catch (EmptyCollectionException e)
                   System.out.println(e.getMessage());
              while (current.getPrevious() != null)
                   current = current.getPrevious();
              DoubleNode<T> temp = current;
              current = temp.getNext();
              size = size - 1;
              return temp.getElement();
         public T removeLast()
              try
                   if (isEmpty())
                        throw new EmptyCollectionException("List");
              catch (EmptyCollectionException e)
                   System.out.println(e.getMessage());
              while (current.getNext() != null)
                   current = current.getNext();
              DoubleNode<T> temp = current;
              current = temp.getPrevious();
              size = size - 1;
              return temp.getElement();
         public T first()
              try
                   if (isEmpty())
                        throw new EmptyCollectionException("List");
              catch (EmptyCollectionException e)
                   System.out.println(e.getMessage());
              while (current.getPrevious() != null)
                   current = current.getPrevious();
              return current.getElement();
         public T last()
              try
                   if (isEmpty())
                        throw new EmptyCollectionException("List");
              catch (EmptyCollectionException e)
                   System.out.println(e.getMessage());
              while (current.getNext() != null)
                   current = current.getNext();
              return current.getElement();
         public int size()
              return size;
         public boolean isEmpty()
              if (size == 0)
                   return true;
              else
                   return false;
         public String toString()
               return "An ordered linked list.";
    }the other file that uses this class:
    import java.io.*;
    import java.util.StringTokenizer;
    public class ListBuilder
         public static void main(String[] args) throws IOException
              String input;
              StringTokenizer st;
              int current;
              OrderedLinkedList<Integer> list = new OrderedLinkedList<Integer>();
              FileReader fr = new FileReader("C://TestData.txt");
              BufferedReader br = new BufferedReader(fr);
              input = br.readLine();
              while (input != null)
                   st = new StringTokenizer(input);
                   while (st.hasMoreTokens())
                        current = Integer.parseInt(st.nextToken());
                        if (current != -987654321)
                             list.add(current);
                        else
                             try
                                  unload(list);
                             catch(EmptyCollectionException f)
                                  System.out.println(f.getMessage());
                   input = br.readLine();
              System.out.println("Glad That's Over!");
         public static void unload(OrderedLinkedList<Integer> a) throws EmptyCollectionException
              while (!a.isEmpty())
                   System.out.println(a.removeFirst());
                   if (!a.isEmpty())
                        System.out.println(a.removeLast());
              System.out.println("That's all Folks!\n");
    }

    i tried @SuppressWarnings("unchecked") and that didnt work. so i ran it and it showed these errors:
    Exception in thread "main" java.lang.NullPointerException
    at OrderedLinkedList.add(OrderedLinkedList.java:30)
    at ListBuilder.main(ListBuilder.java:32)
    Press any key to continue...
    which would be:
              while (current.getPrevious() != null)and:
                             list.add(current);

  • Big generic problem

    I'm having a big problem. Look at this:
    public class Person {
    public class Employee extends Person {
    public class Bank {
    private List<Person> people = new ArrayList<Person>();
    public List<Person> people() {
    return people;
    Now the problem:
    public class Test {
    public static void main(String args[]) {
    Bank b = new Bank();
    b.people().add(new Employee()); // This was to be forbidden, but
    // the compiler doesn't complain
    In the class Bank I declared a list to contain only Person objects:
    private List<Person> people = new ArrayList<Person>();
    and a method to return it, with the same generic type:
    public List<Person> people()
    so, how could the compiler let me add a person of type Employee in the class
    Test? No matter if I change the declaration of the people() method to accept
    only objects of class Person and above, like this:
    public List<? super Person> people()
    it still compiles and I still can add Employee objects to the list that were
    supposed to hold just Person objects.
    So, the question is:
    HOW COULD I RETURN A LIST IN A METHOD WITH A GENERIC TYPE THAT HAS SUBCLASSES AND THAT I CAN MAKE THE LIST TO ACCEPT OBJECTS JUST OF THAT TYPE, NOT OF ITS SUBCLASSES? So, this is type safe. I don't want the list of the example above to accept objects of type Employee, just Person.

    so, why can I add Employees to a list declaredthis
    way
    public List<Person> get() {
    return people; // <--- list of Person
    }I don't see how it can be said any more clearly -
    BECAUSE AN Employee IS A Person!
    wouldn't it be to behave the same way as you
    said?
    Is
    the proplem related to a param and a return
    type.
    With params with works, but not with returntypes?
    I don't understand your point!Look if I'm really understanding this thing:
    public void add(List<Person> p)
    private List<Employee> e = new
    ArrayList<Employee>();
    obj.add(e) // Error. It's not exactly a PersonNow:
    public List<Person> people();
    private List<Employee> e = new
    ArrayList<Employee>();
    obj.people().add(new Employee()); // Ok. But why?An Employee is a Person. But in the first code it
    didn't let me add an Employee to a method acception a
    Person. That's what I want. But why the second code
    worked. Isn't it the same thing. The param type in
    both examples is a list of Person.To be more clear in the first code:
    public class Obj {
        public void people(List<Person> p)
    private List<Employee> e = new ArrayList<Employee>();
    Obj obj = new Obj();
    obj.people(e) // Error. It's not exactly a Person

  • Generic problem in passing arguments  ( question )

    I wrote some generic class that hold some generic map.
    When i looking some key in this map - i want to have the value of the key and set this value to some argument that i pass to the function that look for it.
    I dont want to return the value as return value of the function. ( i must have return value as Boolean )
    My paroblem is that when ever i call this function - i get back the "value" as null - and i dont know why and how to solve this problem.
    public abstract class SomeTable<T, U> extends Table{
          protected Map<T, U> currentTable = new HashMap<T, U>();
         public Boolean findItem(T itemToFind , U value){
                value = currentTable.get(itemToFind);
                return ( value == null );
    }Edited by: Yanshof on Dec 3, 2008 6:02 AM
    Edited by: Yanshof on Dec 3, 2008 6:11 AM

    You don't want to get the value from the key, you want to set it. Something more like:
           public Boolean findItem(T itemToFind , U value){
               currentTable.put(itemToFind, value);
               return (value == null);
            }Maybe you should review the functionality of a HashMap and variable assignment..
    Edit: Unless of course I'm misunderstanding your goal (ejp's post makes me think I am :) )
    Edited by: Pheer on Dec 2, 2008 10:15 PM

  • Generic problem: superdrive malfunction - trying to eject disk?

    I've previously posted this problem on the Powerbook thread, but following my initial problem of not getting a stuck disk out of the superdrive, this seems to have progressed into a more serious issue which may be solved using a generic OSX solution?
    It started a stuck disk in the drive, so I used a credit card and a sharp, very thin letter opener (metal) and used them like tweezers to force the disk out.
    However, now I'm left with a machine that continually tries to eject an imaginary disk, over and over again. But the disk has been forced out by myself.
    Can I over-ride this command in Terminal or somewhere else?
    Thank you in advance.
    C Marks

    Hi Carey,
    Optical drives are all too short lived i my experiences, Slot loading ones the worst.
    This may take a few back & forths, but...
    In Finder, select Go menu>Go to Folder, and go to "/volumes".
    Volumes is where an alias to your hard drive ("/" at boot) is placed at startup, and where all the "mount points" for auxiliary drives are created for you to access them. This folder is normally hidden from view.
    Drives with an extra 1 on the end have a side-effect of mounting a drive with the same name as the system already think exists. Try trashing the duplicates with a 1 or 2 if there are no real files in them, and reboot.
    Safe Boot , (holding Shift key down at bootup), use Disk Utility from there to Repair Permissions, test if things work OK in Safe Mode.
    Then move these files to the Desktop...
    /Users/YourUserName/Library/Preferences/com.apple.finder.plist
    /Users/YourUserName/Library/Preferences/com.apple.systempreferences.plist
    /Users/YourUserName/Library/Preferences/com.apple.desktop.plist
    /Users/YourUserName/Library/Preferences/com.apple.recentitems.plist
    Reboot & test.

  • Intricate generics problem

    I have a problem with this code:
    interface Test<T extends Number> {
        public <U> void test(Test<? super U> t, U value);
    }Sun javac 1.6.0_13 accepts it, Eclipse 3.5.1 says:
    "Bound mismatch: The type ? super U is not a valid substitute for the bounded parameter <T extends
    Number> of the type Test<T>". This, at first glance, seems a valid complaint, but on the other hand, how could there ever be a parameterized Test that is not of type <T extends Number> passed as a parameter?
    So, my question is: which one is right? I suspect javac is correct and Eclipse has a bug here, but why? Is it correct of the compiler to rely on the implicit bounding of all Test objects as defined in the interface declaration to <T extends Number>, or is it correct (as Eclipse's syntax checker does) to demand an explicit one?
    Could anyone point me to the appropriate Java reference paragraph covering this situation?
    Anyway, either javac or Eclipse has a bug here obviously, I'm just not sure which one!
    Edited by: marhaus on Nov 4, 2009 6:50 AM

    What confuses me is why Javac might accept that, but neither accepts this:
    public interface Test<T extends Number> {
        public <V> void test(Test<V> t);
    }If this doesn't work, I certainly understand why your example doesn't. I think it probably has to do with how the V (or U in your case) is inferred, and that's why they differ.
    For instance, consider this:
       public static void main(String[] args) {
          String s = getSomeObj();
       private static <V> V getSomeObj() {
          return null;
       }Here, V is inferred by the fact that you're assigning to a String. Everything compiles fine. But now consider if we changed getSomeObj:
       private static <V> V getSomeObj(SomeClass<V> sc) {
          return null;
       private static class SomeClass<V extends Number> {
       }This now doesn't compile, perhaps because the bounds of V are not determined at all by how it is used in the arguments. Similarly,
       private static <V> SomeClass<V> getSomeObj() {
       Won't compile, for the same reason. So it seems like neither goes into the decision-making of the bounds of V. It seems like the bounds are decided completely by what's in the <V> part.
    If this is all for learning, by all means continue. I would almost say that it's a javac anomaly. But if it's an actual problem, I would say just do this instead:
        public <V extends Number, U extends V> void test(Test<V> t, U value);

  • XCelsius Generic Problems

    Hi everybody,
    I am a corporate user of Crystal XCelsius 2008, and after 3 months using it, I just wanted to post here my opinions on the product and also some of the (big amount) of problems I've found with it in hope they are solved in future versions of XCelsius.
    I find XCelsius a good product overall. It allows for fast deployment of interactive dashboards that are very appreciated by management, allowing for quick and informed decision taking. However, there are a number of issues and problems XCelsius needs to solve in order to become a trully powerfull dashboarding tool:
    - I am running XCelsius 2008 in a brand new Windows XP SP3 laptop with 4GB of RAM, Microsoft Office 2007 and all the latest patches applied. However, XCelsius keeps crashing regularly for no reason whatsoever ("Could not load localized strings" error, "Error loading Excel" error and others). I am now manually saving my work every 3 minutes, but it's a big inconvenience that XCelsius isn't reliable enough.
    - Every time I try to install a new XCelsius version/patch (XCelsius SP2 for instance), the setup stalls on registering modules and never finishes, having to manually kill the process. After much investigation (this forum helped a lot), I found out that this is due to incompatibility problems between XCelsius and McAfee Anti-virus which we use in our computers. This is the only software I've found problems with in this area, and anyway a corporation-oriented software should never ever have this kind of issues.
    - Erratic behaviour. This might seem very strange, but I've found myself (more than once) having to re-enter a formula in the worksheet in XCelsius because the first time it simply didn't work. The second time it works without a problem.
    - The Excel formula support is way too limited. Formulas like SEARCH or SUMIFS (new in Excel 2007) are critical in a data-driven enterprise environment, and not having them available is a big problem.
    - While trying to overcome the above limitation I installed the XCelsius Component SDK to see if I could replicate the functionality of those formulas with custom components. Problem is, although I am fluent in ActionScript and MXML, the SDK documentation is so sparse I could not even figure out how to write my own function.
    - Performance is another issue. When you use a reasonably-sized data set, XCelsius performance degrades exponentially, something not acceptable for corporate customers. I am not talking here about 10's of thousands of rows and columns, but simply 2,000 rows and 15 columns.
    I am simply posting thsi here in the hope that I am not the only user experiencing those issues and that BO listens to its customers and imporves the overall XCelsius experience in the near future.
    Thanks!

    Thanks for your reply and understanding, xzatious. Now I know I am not alone!
    I definately learnt to get used to those errors, but that doesn't make them less annyoing. As for the tip on the Excel process running in the background, thanks but I was already aware of it. But precisely this evidences one of the biggest problems with XCelsius: the poor coding techniques used when developing it.
    Any developer in the world knows one of the first things to implement in the application you are developing is good exception handling, and definately XCelsius is not an example of that. Most of the times, when it crashes, it simply says "Xcelsius.exe has found an error and needs to close" and then it leaves the Excel instance it has been using running in the background. What kind of exception handling is this?!?!? An enterprise-oriented software like XCelsius with its price tag (not cheap!) should be much better developed than this!
    And there's one last issue I forgot to mention, and that's more related to the selling/pricing area: when we bought XCelsius Engage (not Server), it came bundled with Flynet Web Services Generator. This is a very useful piece of software if you don't want/can't/don't have time to write web services yourself. But I had to speak witht eh Flynet guys themselves to discover my copy of Flynet wasn't working because it only works with an XCelsius Engage Server license! Why does it come bundled with regular XCelsius then?!?!?!?

  • Major, generic problems -checkitoutcheckitoutcheckitout

    anyway,
    so all my problems, like everyone else's, started out with 5.0. but all of the actual itunes issues were worked out, and i downloaded 5.0.1 today. it, for the most part is functioning as well, but i can't connect my ipod (i couldn't on 5.0 either). here's what happens
    I plug my iPod in.
    If iTunes is already running, then everything on the computer freezes out until I disconnect it.
    If I plug in the iPod and then try to open iTunes, then everything freezes until I disconnect it, at which time iTunes immediately opens.
    here's what you need to know:
    -"my computer" doesn't recognize the drive (i can only check when ipod is plugged in and itunes is not running) although i've never checked to see if it did anyway.
    -i always get a "hi-speed usb device plugged into non-hi-speed port", but i've always gotten that
    -the last few weeks before downloading 5.0, on 4.9, whenever the ipod was plugged in it would say something about a corrupt file, but then continue as normal.
    -i've had the ipod about 8 months (exactly in 2 days, in fact)
    -the ipod itself is being kinda slow, having trouble playing songs sometimes when an iTrip is plugged into it, but this started yesterday and i've had the iTrip for 5 months (to the day).
    -i am NOT reinstalling itunes again. i've run out of fingers on my hand to count the times i've done this. PER DAY. well, almost.
    -i've already reset the ipod many times
    I think that's it. can anybody help?

    Look for updated drivers for your USB ports. What drivers depends on the brand of your computer, motherboard, or USB card. But the "hi-speed usb device plugged into non-hi-speed port" is the giveaway here. That says that either your USB only supports 1.1 (it's an older computer) or you have older drivers that don't support USB 2.0.
    Likely this will fix many problems. While you're at it, go to Windows Update and install all the updates for the computer. Just install everything you can from there.

  • Mystifying generics problem (or perhaps I am just stupid?)

    Given the following class:
    public class DataTextFileReader<T> {
         private Vector<T> builtVector = null;
         public Vector<T> getData() {return builtVector;}
    }And these instructions in another class:
    DataTextFileReader theFileReader = new DataTextFileReader<Kanji>();
    Vector<Kanji> builtVector = theFileReader.getData();Why do I get an unchecked type warning from the call to getData()?
    Of course, the above code is drastically simplified. In actuality the constructor for DataTextFileReader is like so:
    public DataTextFileReader(File inputFile, LineParser<T> theLineParser)And the line I am instantiating it with is like so:
    new DataTextFileReader<Kanji>(inputFile, (LineParser<Kanji>)new KanjiDetabber());And of course, there is a Kanji class, a LineParser<K> interface, and a KanjiDetabber class which implements LineParser in the picture. LineParser defines a parseLine method used to built objects from lines passed from the DataTextFileReader (in the case of KanjiDetabber, Kanji objects). DataTextFileReader basically just uses the LineParser to build objects which it puts into builtVector, and keeps track of bad lines. I am using this to read in data files in human-readable format so that I can do manual data entry into a text file and then just import everything.
    But all of these compile without errors or warnings, and anyway nothing else should be relevant as long as the builtVector member and the getData() method have the right generics, right?
    I take it I am not the only person who finds generics thoroughly vexing. Useful, but vexing.
    Drake

    Off topic: consider using ArrayList instead of Vector.
    You need to use generics in all places:
    DataTextFileReader<Kanji> theFileReader = new DataTextFileReader<Kanji>();Also, this example:
    new DataTextFileReader<Kanji>(inputFile, (LineParser<Kanji>)new KanjiDetabber());Remove the cast:
    new DataTextFileReader<Kanji>(inputFile, new KanjiDetabber());Make sure that KanjiDetabber is declared like this:
    class KanjiDetabber extends LineParser<Kanji> { ... }Perhaps you would be happier with a different word
    than Detabber, how about KanjiTabFilter.

  • Java Generics problem

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

    user13384537 wrote:
    Firstly thanks for your kind reply .....
    can you please elaborate it more ???? because i am confused too much in generic methods especially ....i am preparing for OCPJP and i am not getting reply for this question any where. You are first to reply this question...Both "? super Number" and "? super K" (indeed, "? super {anything}") represent unknown types with no upper bound. While it's true that they could both, in fact, be 'Number's, the compiler has no way of knowing this, which is why it's invalid for an ABS (because you've already defined it as taking a type that extends Number).
    I'll be flamed if I'm wrong; but that's the way I understand it.
    My suggestion would be to look at the [url http://download.oracle.com/javase/tutorial/extra/generics/index.html]Gilad Bracha tutorial. It's quite long in the tooth, but it's still the best one around, I reckon.
    Winston

  • Quick generics problem

    I understand how generics can be used to put control over the datatype to be stored but I'm not sure about
    the distinct differences in the use of the following. could someone just explain the difference between each of them.
    the first one has String specified in the declaration and creation of the vector, second one has <String> only specifed
    in the decarlation of the vector, and the last only has <String> in the creation of the object.
    Vector<String> vect = new Vector<String>();
    Vector<String> vect1 = new Vector();
    Vector vect2 = new Vector<String>();Thanks,
    newbie

    saru88 wrote:
    I understand how generics can be used to put control over the datatype to be stored but I'm not sure about
    the distinct differences in the use of the following. could someone just explain the difference between each of them.
    the first one has String specified in the declaration and creation of the vector, second one has <String> only specifed
    in the decarlation of the vector, and the last only has <String> in the creation of the object.
    Vector<String> vect = new Vector<String>();
    Vector<String> vect1 = new Vector();
    Vector vect2 = new Vector<String>();
    The second and third definitions will give you compiler warnings. I suggest you add
    vect.add("1");
    vect1.add("1");
    vect2.add("1");
    vect.add(1);
    vect1.add(1);
    vect2.add(1);to your test code and see what you get; it might help explain some things. Come back if you're still confused.
    Winston

  • Incompatible types with generics problem

    Hi,
    I get a mysterious compiler error:
    C:\Documents and Settings\Eigenaar\Mijn documenten\NetBeansProjects\Tests\src\tests\genericstest.java:26: incompatible types
    found : tests.Store<T>
    required: tests.Store<T>
    return store;
    1 error
    BUILD FAILED (total time: 0 seconds)
    in the following code:
    class Supply<T extends Supply<T>>{}
    class Store<T extends Supply<T>>{ }
    class A<T extends Supply<T>>{
        private Store<T> store;
        class B<T extends Supply<T>> {
            public Store<T> getStore(){
                return store;                         <-- compiler error!
    }Any help would be greatly appreciated.
    Edited by: farcat on Jan 13, 2009 1:23 PM

    Note that the type parameter T used to define class B is not the T used to define class A. What you wrote can be more clearly written:
    class Supply<T extends Supply<T>>{}
    class Store<T extends Supply<T>>{ }
    class A<T extends Supply<T>>{
        private Store<T> store;
        class B<U extends Supply<U>> {
            public Store<U> getStore(){
                return store;
    }Which produces the more readable error message:
    A.java:10: incompatible types
    found   : Store<T>
    required: Store<U>
                return store;B, being a nested, non-static class is already parameterized by T:
    class Supply<T extends Supply<T>>{}
    class Store<T extends Supply<T>>{ }
    class A<T extends Supply<T>>{
        private Store<T> store;
        class B {
            public Store<T> getStore(){
                return store;
    }

  • Generic problem for search help without values

    Hi,
    Always I open a search help without values I get the warning popup "No values found" but after this no link let me come back to the previous screen.
    Does anybody know how I can solve this (in a standard way)
    thanks
    regards

    Hi
    It seems to be a bug in the system.
    <b>Please have a look at the following SAP OSS Notes -></b>
    <u>Note 574604 - Various correction reports for EBP business partner
    Note 1028643 - Input help for contact persons in purchase order
    Note 843008 - EBP4.0 and higher: Terms of Payment, Texts and codes
    526416 Structural enhancements LFA1
    698246 EBP 4.0 address maintenance: Default address for address use
    701321 EBP 3.5 address maintenance: Default address for address use
    701323 EBP 3.0 address maintenance: Default address for address use
    701384 BBP 2.0C address maintenance:Default address for address use
    690619 Plants are not transferred during location replication
    641960 New processing of terms of payment in EBP 3.5
    628386 Incorrect link for EBP for 'External business partners'
    Note 544392 Error in search helps EBP 2.0
    Note 544816 Error in search helps EBP 3.5
    Note 544713 Error in search helps EBP 3.0</u>
    Please raise a customer OSS message with SAP as well.
    Regards
    - Atul

  • USB Ethernet generic problem on yosemite

    Hi
    i had buy third party USB to Ethernet it's not working with my MBA Yosemite version
    i had seen driver on USB
    but it's doesn't show ethernet on Preferences>Network
    what should i do?

    That's not a panic log. If you have more than one user account, you must be logged in as an administrator to carry out these instructions.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Select the most recent panic report (with a name that begins with "Kernel" and ends in ".panic") under the heading System Diagnostic Reports on the left. If you don't see that heading, select  
    View ▹ Show Log List
    from the menu bar. Post the entire contents of the report — the text, please, not a screenshot. In the interest of privacy, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post any other kind of diagnostic report, such as a hang report.

  • Tricky Generics problem covariant return types

    Consider the following classes
    class A {
    class B extends A {
    class C {
    public <T extends A> T foo(Class<T> cls) {
    System.out.println("A");
    return null;
    class D extends C {
    public <T extends B> T foo(Class<T> cls) {
    System.out.println("B");
    return null;
    public static void main(String[] args) {
    D d = new D();
    d.foo(B.class);
    This will print "B" as one would expect. But if change main() to be like this:
    C d = new D();
    d.foo(B.class);
    Then it will print "A". In other words, public <T extends B> T foo(Class<T> cls) does not override public <T extends A> T foo(Class<T> cls)
    Rather dangerously apparently, the method that gets called doesn't depend on the object type but upon the variable type holding the reference. No dynamic binding.
    Can anyone explain to me the logic of why <T extends B> shouldn't be a covariant subclass of <T extends A> and thus be overriding the superclass method?

    Hello chrisbitmead,
    what should the following print?
    C d = new D();
    d.foo(A.class);If D.<T extends B>foo(Class<T>) overrode C.<T extends A>foo(Class<T>) it would print B, even though A.class does fall within the required bounds.
    With kind regards
    Ben

Maybe you are looking for