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.

Similar Messages

  • I tried to restore my iphone but when it was restoring it said a problem occurred and now it just shows the itunes symbole and its telling me to connect to it but when i try to it  doesnt show up on my computer

    i tried to restore my iphone but when it was restoring it said a problem occurred and now it just shows the itunes symbole and its telling me to connect to it but when i try to it  doesnt show up on my computer

    Hi there starbaeza,
    You may find the information in the article below helpful.
    iOS: Forgotten passcode or device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    -Griff W. 

  • I have a new laptop so I download again iTunes...the problem here is that I just got a cd and I tried to put it on my iPod and it won't let me, how can I fix this?

    I have a new laptop so I download again iTunes...the problem here is that I just got a cd and I tried to put it on my iPod and it won't let me, how can I fix this?

    The iPod sees the new computer as a new iTunes library. You can only sync with one iTunes library.  However, you can manage music among disfferent computers.  See:
    Using iPhone, iPad, or iPod with multiple computers

  • Hi, my facebook app on my Ipad3 has stopped allowing me to put comments on. Does anyone have any ideas how to correct this? Don't know if it is a problem with the Ipad or just the facebook app. Thanks.

    Hi, my facebook app on my Ipad3 has stopped allowing me to put comments on. Does anyone have any ideas how to correct this? Don't know if it is a problem with the Ipad or just the facebook app. Thanks.

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime: Set-up, Use, and Troubleshooting Problems
    http://tinyurl.com/32drz3d
    I saw one post where a user said dust got inside the small microphone hole. Using a vacuum cleaner removed the dust and restored the audio.
     Cheers, Tom

  • I HAVE NO PROBLEM WITH FIREFOX. I JUST WANT THE SPACE FOR OTHER SERVICE.

    I HAVE NO PROBLEM WITH FIREFOX. I JUST HAVE TOO MANY THINGS ON MY BROWSER AND WANT TO MAKE POSITIVE CHANGES. HOW CAN I UNINSTALL FIREFOX SUCCESSFULLY? THANK YOU.

    if you want to make a clean start again, create a new profile!
    see [[Managing profiles]]
    edit: and afterwards you might want to go into addons-manager > plugins & disable all stuff in there you won't need/use any longer...

  • After updating to ios6. I am unable to have voice control in my Fiesta Titanium has this been a problem for anyone else or just my problem?

    After updating to ios6. I am unable to have voice control in my Fiesta Titanium has this been a problem for anyone else or just my problem?

    I am an activist when it comes to rip-offs and I intend to set up a group to pressure the Ausralian government to legislate to make all computer software producers to make all new software compatible with all old software AT NO COST to the user.
    I thought about that myself, but when it comes to Windows XP. It is peculiar that software companies get away with "selling" software that suddenly stops working properly. The problem with XP is of course an environmental one as well. There is a huge number of fully functional PCs that suddenly are no longer supported by Microsoft, and that are not powerful enough to take newer supported MS operating systems. What MS basically recommends people is to throw them away with a horrible cost for our environment.

  • Is anyone having problems with the facebook app - just shuts down before it even loads - frustrating!

    Is anyone having problems with the facebook app - just shuts down before it even loads - frustrating!

    Hi Robk573,
    Thanks for visiting Apple Support Communities.
    I'd suggest the steps in our iPad troubleshooting assistant:
    https://www.apple.com/support/ipad/assistant/application/
    Best,
    Jeremy

  • Hello guy, i have a problem when playing the FL commando which when i am playing the game , sudden the game is log out by itself. I would like to know what is the problem for my ipod 4g, just buy recently only and having ios 5.0.1

    Hello guy, i have a problem when playing the FL commando which when i am playing the game , sudden the game is log out by itself. I would like to know what is the problem for my ipod 4g, just buy recently only and having ios 5.0.1

    - See:      
    iPod touch: Hardware troubleshooting
    - Try another cable. Some 5G iPods were shipped with Lightning cable that were either initially defective or failed after short use.
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar      

  • 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);

  • Vine.co can not watch videos on other browsers do not have the problem with firefox firefox there just did not work, delete cookies, history

    vine.co can not watch videos on other browsers do not have the problem with firefox firefox there just did not work, delete cookies, history

    I think this problem may be caused by Yahoo's changes making it incompatible with the klatest version of FireFox.
    This is suddenly affecting many many people who use Firefox and are members of Yahoo Groups. All these people say they themselves changed nothing and have not been locked out before when using Firefox. But suddenly, within the last week, they are.
    What did Mozilla do or what did Yahoo do to cause this problem? I can say that I was not blocking cookies and after trying a number of things to fix it, I went to Yahoo's home page and navigated to my group from here.
    This problem is not anything a user did. Either Firefox is at fault or Yahoo is. I want to know which company is at fault and when they are going to fix it.

  • Can you delete videos from itunes? it's just stupid if you can't.

    why can't you just right click "clear?" you can copy, but you can't delete them? that's just stupid. i didn't even buy them from the itunes store, i got them from some website. they won't play on my ipod so I really don't need them in itunes....thanks for whatever help you can give me. i already deleted them from my hard-drive but they still show up in itunes for some dumb reason.......
    ~chris

    No Problem!
    Might want to mark my post solved or answered at the top of the thread so it shows as answered and we can refer here. Believe it or not, this question has popped up several times before
    btabz

  • Hi there , i use microsoft remote desktop to connect to my work pc - on my 21.5 mac the remote screen is half the size of my screen and i cant get it to be full screen - is this possible or am i just stupid ? many thanks

    Hi there , i use microsoft remote desktop to connect to my work pc - on my 21.5 mac the remote screen is half the size of my screen and i cant get it to be full screen - is this possible or am i just stupid ? many thanks

    What setting have you chosen in the view menu? Fit to Screen or Window.
    And, in Preferences what have you set for Display?

  • I just purchased a movie and I can't get the iTunes extras to play, the unrated version plays but I want to watch the special features . Am I just stupid or is there something simple I am not seeing?

    I just purchased a movie and I can't get the iTunes extras to play, the unrated version plays but I want to watch the special features . Am I just stupid or is there something simple I am not seeing?

    Hello there, NighHawk420.
    The following Knowledge Base article provides some practical information on where to locate the iTunes Extras when purchased with a movie from iTunes:
    About iTunes LP and iTunes Extras
    http://support.apple.com/kb/HT3823
    When you purchase a movie with iTunes Extras, the primary movie along with the iTunes Extras will download to your iTunes Movie folder. Mouseover the cover art and click the icon on the album to open the main menu to play the movie or view other features.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • 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);

  • 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

Maybe you are looking for

  • Problems trying to insert rows from PL/SQL procedure with existing seq..

    hello. please help me. i have a button that is calling an anonymous PL/SQL block and i am struggling with inserting records automatically when this button is clicked. an ordinary before insert DB trigger is launched: reate or replace TRIGGER "SPECSYS

  • Unable to install

    Okay I've downloaded iTunes but can't seem to get it installed. I've tried deleting and redownloading & rebooting the computer but can't seem to get the install window to come up. I have an icon on the desktop for "setup" but I keep getting the windo

  • Selecting data from table

    Hi just have a Labview programming question that I'm not too sure how to implement. Right now I have a VI that takes in an Excel file and dumps the values onto a 2D table. I'm extracting individual columns of values from the table by using "delete fr

  • Multiple iPods using One Computer

    Over the past two years, I have acquired an iPod Mini, iPod Shuffle, and most recently an iPod nano. I have loaded iTunes for the iPod Mini, but don't want to have 3 versions of iTunes on this one computer (my wife wants to use one of the othe iPods)

  • Can Photoshop or Lightroom utilize double-precision capable GPUs for photographic image editing.

    Hello - I need to upgrade my graphics card.  Question can either Photoshop CS5 or Lightroom 5 utilize doubleprecision capable GPUs?  Thanks much for your help. Background: Application- photographic RAW files editing (no video editing.) Software- Phot