Removing unchecked call warnings

I have moved from 1.4.2 to 1.5.0 today, and now I'm trying to solve all the unchecked call warnings that I had in the code, but I have one that I don't know how to avoid it.
I need a matrix of nxn dimensions where every element is an Integer. I was creating this matrix in a recursive way, with a recursion deep of n. For example, if n=3, I had finally a Vector<Vector<Vector<Vector<Integer> > > >. As n is configurable by the user, I can't determine the data types that i must declare in the recursive calls that I use to manage the matrix.
There is a class to implement my "matrix" in a simplest way?
If not, there is a way to remove the warnings in the recursive calls?
If not, I suppose that I must keep the warnings...
Jorge

Well, my use of the matrix is not mathematical but to represent the "real world".
I'm working in the project previous to the University graduation, and I'm implementing a communication protocol among different computers.
Those computers are linked in n dimensions (I have let configurable the dimensions because I think that flexibility is important for things like this).
If n=1, the computers are linked like this:
A - B - C -D - E -F - G - H - J
If I have n = 2 the computers are linked like this:
A - B - C
| \ | / |
D - E - F
| / | \ |
G - H - J
(Well, in the post preview this last configuration looks very bad because some spaces are trim: The "E" computer is linked to all the rest of computers)
If I have n = 3 the computers are linked in a cube shape, if I have n = 4 in an hipercube, and so on.
That's why I need a multidimensional matrix to represent my network.
I have a class that encapsulates the access to all the linked neighbours of a computer, and internally it stores these neighbours as a Vector of Vector's. of Vector's...(n times)
For example, to create all the neighbour objects, I must write code like this:
private Vector neighbours; // I don't know what I must write inside <> next to Vector declaration
neighbours = new Vector(LINKS_IN_DIMENSION); // Again, the warning complains the lack of <>, but I don't know what goes inside
initializeDimensionVector(1, neighbours);
// In the method declaration, I need again the <> specification but is not possible
private void initializeDimensionVector(int dimension, Vector vecDimension)
     vecDimension.setSize(LINKS_IN_DIMENSION);
     if ( NET_DIMENSIONS == dimension )
          for ( int i = 0; i < LINKS_IN_DIMENSION; ++i )
          vecDimension.setElementAt(new NeighbourDirectlyConnected(), i);
          return;
     for ( int i = 0; i < LINKS_IN_DIMENSION; ++i )
          // And finally here, for the new recursive call, the unspecified Vector declaration appears again
          vecDimension.setElementAt(new Vector(LINKS_IN_DIMENSION), i);
          initializeDimensionVector(dimension + 1, (Vector)vecDimension.elementAt(i));
}The number of dimensions n is represented by NET_DIMENSIONS.
The other constant (LINKS_IN_DIMENSION) tells how many different indexes we have per dimension.
Hope this sample code explains a little bit what I'm trying to do.
I can close my eyes and forget the warnings, but I come from the C++ world and experience tells that warnings musn't be ignored.
Regards and thanks for your help.
Jorge.

Similar Messages

  • Unchecked call

    I am creating a Avl tree that will work with any type of object and am getting unchecked call warnings with calls to compareTo.
    private Node insert(Comparable user, Node newNode)
              if(newNode == null)
                   newNode = new Node(user);
                   count++;
              else if((user.compareTo(newNode.getObj())) < 0)
                   newNode.setLeft(insert(user, newNode.getLeft()));
              else if((user.compareTo(newNode.getObj())) > 0)
                   newNode.setRight(insert(user, newNode.getRight()));
              else
                   System.out.println("Duplicate names not allowed, data not entered into tree");
              //make sure to check for duplicate handles, should be caught in signup
              return newNode;     
    public int compareTo(Object o)
              if ( !(o instanceof User) )
                   return 0;
              User rhs = (User)o;
              if(id < rhs.getId())
                   return -1;
              else if(id > rhs.getId())
                   return 1;
              return 0;//should never happen
         }How do i get rid of the compiler warnings while maintaining the abitilty to use the tree with any type of object.
    Is it just me or is all this new stuff more trouble then it is worth and makes java as ugly syntactically as C++.

    Don't be a pompous as's. I would spend the time
    learning it, if it had any value or advantage to it.
    3 casts in 1 class vs generics crap scattered in 3
    and both are equally safe.hang on a minute.
    You post code that doesn't demonstrate your problem, because it calls methods setLeft and setRight on a class (Node) we may or may not have source code for because your two methods have no enclosing class. I can't just take your code, compile it, see the error message, find a solution for you and post it back. No I have to try and work out all the bits that are missing.
    Further, your question is ambiguous so I ask which of two possible solutions you want, and give you a hint toward the solution for each. My intention there was that either you could run with the hint and solve the problem yourself, or you could come back and answer the question and we could then proceed to find a solution.
    But what happens? Neither. You just give up. Even a 3 year old knows that stubbing your toe is no excuse to go back to crawling.
    If you have no inclination to solve your problem, why did you post it in the first place?
    If I've still got your attention, then if you ever decide to retry generics, may I suggest you start simple, using the generic collections in your own classes.
    Don't try creating your own generic classes till you are confident using the ones crafted by people who had a pretty good idea of what they were doing.
    P.S. If you want to answer the question, and post something that compiles (albeit with warnings) I'd still be keen to find a solution with you.

  • Warning: [unchecked] unchecked call to getMethod when updating to JDK 1.6

    I'm received the following compilation warnings after I switched to Java 6 from Java 5:
    warning: [unchecked] unchecked call to getMethod(java.lang.String, java.lang.Class<?>...> as a member of the raw type java.lang.Class
    removeChangeListener = myParent.getMethod("removeChangeListener",
    changeListenerParameterTypes);
    The code is this class is instantiated by many classes. The class instantiating this class is passed through a constructor.
    Here is a partial code snippet of the class, constructor and method where the warning occurs:
    public class DumpDisplay extends javax.swing.JFrame implements javax.swing.event.ChangeListener
    private Class changeListenerParameterTypes[] = new Class[2];
    public DumpDisplay(Object mvc)
    Class myParent = mvc.getClass();
    public void removeListeners()
    Method removeChangeListener = null;
    changeListenerParameterTypes[0] = ChangeListener.class;
    changeListenerParameterTypes[1] = Integer.TYPE;
    // Get the removeChangeListener method from the MVC class
    try
    removeChangeListener = myParent.getMethod("removeChangeListener",
    changeListenerParameterTypes);
    catch (NoSuchMethodException e)
    System.out.println(" DumpDisplay class addChangeListener method: "+e);
    This compilation warning does not appear in JDK 1.5. Any assistance is greatly appreciated.

    Class myParent = mvc.getClass();Class<?> myParent = mvc.getClass();

  • Unchecked call to to add(E) ....... HELP

    Hi, i was doing a project in eclipse, and everything was fine (compiled and running). However, I ran into this problem when I try to compile the same code in DOS command line. Is there any ways that I can fix this problem so the same code that runs in Eclipse can compile in DOS also?
    a glimpse of the code is below:
    ArrayList best_move  = new ArrayList();
    for ( ..r... )
       for( ..c.... )
           Move  move = new Move( r, c);
           if( move is valid )
                then
                    best_move.add(move);warning: [unchecked] unchecked call to add(E) as a
    member of
    the raw type java.util.ArrayList
    best_move.add((Move) move);Appreciate your help.

    try the following
    ArrayList<class name> best_move  = new ArrayList<class name>();
    for ( ..r... )
       for( ..c.... )
           Move  move = new Move( r, c);
           if( move is valid )
                then
                    best_move.add((class name)move);in above "class name" is the class of the object which u wanna store in the collection e.g java.lang.Integer or java.lang.Float etc.
    this will not give any warnings in jdk1.5 and will help u out.

  • JDK 6: Generics: List.add() question - keep getting unchecked call warning.

    JDK 6
    Generics
    private TreeNode transactionTreeData;
    transactionTreeData.getChildren().add(moduleData);1. transactionTreeData is a TreeNode.
    2. the method getChildren() returns a java.util.List
    3. the method add() is from the Collection interface.
    I keep returning the warning message:
    "unchecked call to add(E) as a member of the raw type java.util.List"
    I understand what this means, but I am having problems rewriting these lines correctly to remove the warning.
    I've tried:
    private TreeNode transactionTreeData;
    List<TreeNode> treeList = transactionTreeData.getChildren();
    treeList.add(moduleData);But I keep returning the same warning message. I guess what is throwing me off is how to I properly add the generic statements when the List is return from a method (getChilden in this example)?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    This is actually JSF - MyFaces Tomahawk to be exact, my mistake for not adding that in my original thread.
    I am dealing with the compiled class:
    package org.apache.myfaces.custom.tree2;
    public interface TreeNode extends java.io.Serializable {  
         java.util.List getChildren();
    }TreeNode.getChildren return a raw List as you can see, no doubt...
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How do I remove my caller id from my samsung convoy phone so that the person I call does not see my name?

    How do I remove my caller id from my samsung convoy phone so that the person I call does not see my name?

    MojaveMoon's solution will work if there is only one person you want to block your ID from; if you want to block your caller ID from everyone, you can go to your account online, go to Change Features, and scroll down till you see Caller ID block.  Instructions say that once this is activated, you can dial *82 before any # you WANT to display your number to, but all others will be blocked.
    If you are on a Family share plan, the account owner needs to log in and choose your line to activate this feature.

  • How to avoid "unchecked cast" warnings

    Hi all,
    here is my code:
    private Vector<String> vector1;
    private Vector<String> vector2=new Vector<String>();
    vector1=(Vector<String>)vector2.clone();
    ...How can i avoid "unchecked cast" warnings, while compiling with "-Xlint:unchecked" option.

    I'd also add that you should think about the following idioms:
    1. Ask yourself do I really need a synchronized structure? The answer might be that unsynchronized structure like ArrayList might be more appropriate. If you DO need a concurrent structure then you may find high-performance one in java.util.concurrent package.
    2. Using interfaces will be more appropriate in the long run:
    List<String> l = new ArrayList<String>(); because you can replace the implementation of the specific interface with more appropriate structure just on one place.
    Best regards,
    Andrej

  • Unchecked call to TreeSet

    So, I'm trying to do something which I thought was fairly simple.
    I have a very simple record class who's only members are two strings and then there are the usual set/get methods. Let us call it class Foo.
    Now, I want to have a set of Foo's which keeps ordering based on first member, second member (e.g., like lastname, firstname). So, I build FooComparator which implements compare and equals. I then create my set class like this:
    public class FooSet extends TreeSet {
            public FooSet() {
            super(new FooComparator());
    }and I get:
    FooSet.java:23: warning: [unchecked] unchecked call to TreeSet(java.util.Comparator<? super E>) as a member of the raw type java.util.TreeSet
    super(new FooComparator());
    FooComparator looks like this:
    public class FooComparator implements Comparator, Serializable {  
            public FooComparator() {
            super();
        //impl of compare() and equals()
    }My two questions are:
    1) Is this warning ignorable?
    2) If not, what is the correct fix?
    Thanks, everyone.
    Best,
    Glenn

    The warning isn't a biggie... I'm pretty sure it's because you're not using generics. So lets say your your record class is called FooRecord. If you changed your code around to this, it should be fine.
    public class FooSet extends TreeSet<FooRecord> {
            public FooSet() {
                super(new FooComparator());
    }There might be a cleaner way to implement this (I'm not too clear on generics) but I'm pretty sure that'll do the trick. Once you get into generics they're awesome and make things a hell of a lot easier.
    -Thomas

  • Unchecked Call to addElement(E)

    I'm trying to store AudioClip objects in a vector. It compiles with a warning:
    AudioHolder.java:19: warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector
              soundVector.addElement(temp);
    Temp is an AudioClip, but even when I make it something simple like an int or a String, it still throws up the same warning. At runtime, the line of code comes up with a nullpointer error. Can someone help me figure out how to fix this?

    The unchecked warning is just that: a warning, which you can safely ignore. All it's saying is that you could have taken advantage of the greater type-safety provided by jdk1.5 generics, for example:  Vector<AudioClip> soundVector = new Vector<AudioClip>();
      AudioClip temp = getAudioClip(); // or whatever
      soundVector.addElement(temp);  // no warningThe NullPointerException is not related to the unchecked warning. You probably tried to call a method or access a field on a null reference.

  • "unchecked call to put(K, V)..."

    Hi, I was till recently using this passage -
    public static final Hashtable map = new Hashtable();
    static {
    map.put(TextAttribute.FONT, new Font("Serif", Font.PLAIN, 14));
    to enable me to pass map into an AttributedString constructor.
    On upgrading to j2se 1.5, I now get this warning from javac: "unchecked call to put(K, V) as a member of the raw type java.util.Hashtable"
    Can anyone explain to me what this means and what to do? (Can't find any of these words in the API).
    Thanks
    Tom

    try here:
    http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
    In Java 1.5 you can type what goes into the collection to stay away from runtime casting errors.

  • Rewrite  process and remove the call to f-54 and replace with bapi proces

    Hi Gurus,
    Please help me to find the soultion.
    The root cause of this continual problem is the design and use of BDC session for F-54.  Is there a redesign possible with ECC6.0?
    I wanted to rewrite the process and remove the call to f-54 and replace with bapi process.
    if this is now possible in ECC 6.0
    The benefit would be to better control what PO was used in the DP recoupment.
    Thanking you,
    Raju Singhireddy.

    Hi Balaji,
    Check this BAPI
    BAPI_QUOTATION_CREATEFROMDATA
    BAPI_QUOTATION_CREATEFROMDATA2
    BAPI_CUSTOMERQUOTATION_CHANGE
    Regards
    Arun

  • Unchecked call: stack.push()

    Hi,
    When I compile my stack program I get an error saying unchecked call for the following line, where variable "s" is my stack, and tempno is a double I'm trying to push onto it:
    s.push(tempno);
    any ideas?

    Stack s = new Stack();
    obviously have
    import java.util.Stack;
    at the top. bit of a n00b at this kind of thing so not sure what this problem is at all!

  • What is this? -- unchecked call to put(K,V)

    unchecked call to put(K,V) as a member of the raw type java.util.HashMap
    m.put( args[0], new Double( args[1]));
    I have code that stores a string and a double value in a map like this:
    String args[];
    m.put( args[0], new Double( args[1]));
    but I get this message when compiling with the Xlint option in javac. Why is this happening?

    Yes. I got the same compile warning when I compile with jdk1.5[jdk-1_5_0_03-windows-i586-p.exe]
    This:
    Map map=new HashMap();
    map.put("abc","def");Will get the warning like "unchecked ....."
    ====
    This:
    Map<Object,Object> map=new HashMap<Object,Object>();
    map.put("abc","def");Will compile OK.
    ====
    Is the compiler's responsible to set the default type to Object?

  • Unchecked Call to addElement(E)(resultset with vector)

    Please i am trying to retreive a number of rows with two columns and am trying to add it into a vector object and ots been giving me this error message.
    Unchecked call to addElement(E)
    my code will appear below
    import java.io.*;
    import java.sql.*;
    import com.ecom.util.*;
    import java.util.Vector;
    public class ProdCategory implements Serializable
         Vector catid=new Vector();
         Vector catname=new Vector();
         EcomConnection econ;
         Connection con=null;
         ResultSet rs=null;
         Statement stat = null;
    /*The following method is used to retrieve the values of category Id and category name from CategoryDet table */
         public String getselect()
              try
                   System.out.println("Getting IN");
                   econ = new EcomConnection();
                   con=econ.getConnection();
                   stat=con.createStatement();
                   System.out.println("Connected...");
                   String query="select Ctgry_Id,Ctgry_Name from CategoryDet";
                   System.out.println("Executing Query");
                   rs=stat.executeQuery(query);
                   System.out.println("Executing result set");
                   while(rs.next())
                        catid.addElement(rs.getString(1));
                        catname.addElement(rs.getString(2));
                   System.out.println(" ");
                   rs.close();
                   stat.close();
                   econ.releaseConnection();
                   System.out.println("Connection Closed");
                   return " ";
              catch(SQLException sqlex)
                   System.out.println("There is some problem in SQL Execution..." + sqlex);
                   return "There is some problem in SQL Execution..." + sqlex;
              catch(Exception ex)
                   System.out.println("There is some other problem " + ex);
                   return "There is some other problem ..." + ex;
         /*The following method is used to get the value of catid variable*/
         public Vector getcatid()
              return catid;

    i mearnt to say warning not errors i tried to typecast
    as in: Vector<string> catid=new Vector();
    Vetor<String> catname=new Vector();
    its stop giving me a warning but didnt work at run-time..it was saying nullpointer exception i need assitance

  • Unchecked call to add element

    I get the following warning:
    warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector
    from the line:
    ((Vector)results.get( "ALL" )).addElement( new Result( date, home, hg, ag, away ) ) ;I have had no problems fixing this warning with simple lines like:
    private Hashtable<String,Object> results = new Hashtable<String,Object>() ;but as you can see it is a bit more tricky.
    The compiler highlights:
    ( new Result( date, home, hg, ag, away ) ) ;as the warning. The Result Object takes parameters <String,String,Integer,Integer,String> if that helps.
    Can anyone suggest how to fix this warning please?

    Are all values in your hastable vectors of results, or will that only be true when the key is "ALL". If they all contain Vectors you can rewrite the code as follows
    private Hashtable<String, Vector<Result>> results = new Hashtable<String, Vector<Result>>();
    results.put("ALL", new Vector<Result>());
    results.get("ALL").addElement(new Result (date, home, hg, ag, away));Or if you want to keep your code more flexible change Vector to it's interface List. That will reduce the amount of work you have to do if you decide you don't want to use Vectors any more and use ArrayLists.
    private Hashtable<String, List<Result>> results = new Hashtable<String, List<Result>>();
    results.put("ALL", new Vector<Result>());
    results.get("ALL").add(new Result (date, home, hg, ag, away));Of course none of this will work if your map contains values other than Vectors of results.

Maybe you are looking for