Is it possible to avoid unchecked cast warning here?

  interface MyRemote extends java.rmi.Remote {}
  public <T extends java.rmi.Remote> Class<T>[] getRemoteInterfaces() {
    return (Class<T>[]) new Class[] { MyRemote.class };  //  <-- unchecked cast
  }

public Collection<Class<? extends Remote>>
getRemoteInterfaces() {
Collection<Class<? extends Remote>> c = new
ArrayList<Class<? extends Remote>>(1);
c.add(MyRemote.class);
return c;
}Just for comparison, without judgement over applicability:
public Collection getRemoteInterfaces() {
    List list = new ArrayList(1);
    list.add(MyRemote.class);
    return list;
}/k1

Similar Messages

  • 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

  • How to get rid of this unchecked cast warning?

    Vector<Integer> v1 = new Vector<Integer>(); // ok
    Object obj = (Object) v1; // ok
    Vector<Integer> v2 = (Vector<Integer>) obj; //unchecked cast
    It works when I try to cast Vector<Integer> to Object. However, it prompts "unchecked cast warning" when I try to cast the object back to Vector<Integer>. How can I get rid of this warning? Is there something wrong?

    There is nothing wrong (it is just a warning).
    In the new type system, you would later do something like
    Integer n = v2.get(14);Now the compiler cannot check (compile time maybe, run time never) whether obj is of class Vector<Integer> (Only Vector), as at compile time as type parameters are stripped away in java1.5 at run time ("type erasure").
    So later the assignment to n could throw a class cast exception at run time.

  • Possible solution for unchecked casts?

    Proposal: add to java.lang.reflect.Type the following methods:
    /** Determines if the specified Object is assignment-compatible with the object
    * represented by this Class. This method is the dynamic equivalent of the
    * Java language instanceof operator. The method returns true if the specified Object
    * argument is non-null and can be cast to the reference type represented by this Class
    * object without raising a ClassCastException. It returns false otherwise.
    public boolean isInstance(Object obj)
    * Casts an object to the class or interface represented by this Class object.
    * Checks all fields in the object that they are of the proper type by calling
    * types.class.instanceof() recursively.
    public T Class.cast(Object obj, java.lang.reflect.Type ... types)
    Then any unchecked cast
    Object obj;
    T0<T1, .. Tn> checked = (T0) obj;could implicitly be converted to:
    Object obj;
    T0<T1, .. Tn> checked = T0.class.cast<obj, T1.class, ... Tn.class);No more unchecked casts in the compiled classes!

    Well, neither the code above nor the code referenced
    in the link to the other discussion above compiles with the
    1.5.0 beta compiler :)
    But the referenced example does! To be sure, here's the faulty but compilable example again:
    public class HiddenCheckedExceptions
      public static void main(String argv[])
        throwHidden(new Throwable());
      public static void throwHidden(Throwable t)
        ExceptionHider a = new ExceptionHider(t);
        ExceptionHider<RuntimeException> b = a;
        b.throwHidden();  // this is line 8
      private static final class ExceptionHider<T extends Throwable>
        private final T t;
        ExceptionHider(T t)
          this.t = t;
        void throwHidden() throws T
          throw t;
    }When running it throws:
    Exception in thread "main" java.lang.Throwable
            at HiddenCheckedExceptions.main(HiddenCheckedExceptions.java:8)Either a ClassCastException should be thrown during the assignment of a to b, or it should not compile at all.

  • Warning: [unchecked] unchecked cast.

    Hello!
    I have a problem with this code.
    I get:
    warning: [unchecked] unchecked cast.
    How should i do the cast?
    Or is it something else that i have done wrong?
    Socket socket = new Socket("localhost", this.port); 
    LinkedList<String> times = new LinkedList<String>();
    ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
    try
        times = (LinkedList<String>)ois.readObject();
    catch(ClassNotFoundException cnfe)
    }

    That's because it is not 100% sure (at compile time) that the object is really of a type LinkedList<String>, that's why you received a warning (note that this is just a warning: not an exception or error). You cannot do anything about is. You could suppress the warning like this:
        @SuppressWarnings("unchecked")
        void yourMethod() {
            try {
                Socket socket = new Socket("localhost", 666); 
                LinkedList<String> times = new LinkedList<String>();
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                times = (LinkedList<String>)ois.readObject();
            } catch(Exception cnfe) {
                cnfe.printStackTrace();
        }Good luck.

  • Warning: [unchecked] unchecked cast found

    I am getting the following warning when I compile my code. Please help.
    warning: [unchecked] unchecked cast
    found : java.lang.Object
    required: java.util.Vector<java.lang.Long>
    copy.path = (Vector<Long>) this.path.clone();
    1 warning
    Here is the code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package cs572project1;
    import java.util.*;
    * Richard Becraft
    * 1/22/2010
    * CS 572 Heuristic Problem Solving
    * This class represents a node in a search tree of a graph that represents a street map.
    public class SearchNode implements Cloneable {
    public long depth;
    public double costSoFar;
    public double estimatedCostToGoal;
    public Vector<Long> path;
    public SearchNode() {
    depth = -1;
    costSoFar = -1;
    estimatedCostToGoal = -1;
    path = new Vector<Long>(20, 20);
    public void printSearchNode() {
    System.out.println("\n****In printSearchNode");
    System.out.println("depth: " + depth + " costSoFar: " + costSoFar + " estimatedCostToGoal: " + estimatedCostToGoal);
    for (Enumeration<Long> e = this.path.elements(); e.hasMoreElements();) {
    System.out.println(e.nextElement());
    System.out.println("****Exiting printSearchNode\n");
    @Override
    public SearchNode clone() {
    SearchNode copy;
    try {
    //System.out.println("in clone SearchNode");
    copy = (SearchNode) super.clone();
    copy.path = (Vector<Long>) this.path.clone(); // <<<< the offending line
    //copy.path = new Vector<Long>(this.path.capacity());
    //this.printSearchNode();
    //System.out.println("copy.path.size: " + copy.path.size());
    //System.out.println("this.path.size: " + this.path.size());
    //System.out.println("copy.path.capacity: " + copy.path.capacity());
    //System.out.println("this.path.capacity: " + this.path.capacity());
    //Collections.copy(copy.path, this.path);
    } catch (CloneNotSupportedException e) {
    throw new RuntimeException("This class does not implement Cloneable " + e);
    return copy;
    }

    rickbecraft wrote:
    I am getting the following warning when I compile my code. Please help.
    warning: [unchecked] unchecked cast
    found : java.lang.Object
    required: java.util.Vector<java.lang.Long>
    copy.path = (Vector<Long>) this.path.clone();The variable path has a type of Vector but clone() returns an Object. It is only a warning, not an error, so you can ignore it - I think you can be confident that clone() will always return a Vector. A slightly more typesafe approach (in my opinion) is to create a new Vector<Long> using the constructor that takes a Collection as an argument, passing in the Vector that you want to clone. Something like
    copy.path = new Vector<Long>(this.path);

  • Unchecked Cast

    i have a code fragment
    Map<Integer,Settore> settori = (Map<Integer,Settore>) sessione.getAttribute("settori");
                if (settori == null) {
                    sessione.invalidate();
                    request.setAttribute("messaggioErrore", messaggioErrore1);
                    getServletContext().getRequestDispatcher("/errore.jsp").forward(request, response);
                    return;
                }that produce this warning (compiling with -Xlint)
    C:\Users\Nino\Documents\Workspace_NetBeans\GEM10\src\java\control\Aggiungi.java:85: warning: [unchecked] unchecked cast
    found   : java.lang.Object
    required: java.util.Map<java.lang.Integer,model.Settore>
                Map<Integer,Settore> settori = (Map<Integer,Settore>) sessione.getAttribute("settori");i can't understand why...why an unchecked cast!
    "settori" attribute is a Map<Integer,Settori>!
    Someone can help me please?

    this is a compile time warning; java can only know during runtime what type of object will actually be in the session; because the session is defined as an <Object,Object> map you can put basically anything in there, which is the flexibility you would expect from the session.
    To the compiler however you are now casting an Object to a <Integer, Settore> map, which COULD go wrong during runtime. Hence the unchecked warning, it is only there to make sure you know what you are doing, meaning you have to add the unchecked annotation.

  • Unnecessary cast warning...I can't figure out why

    I've got my compiler warning me of unnecessary casts, and this method generates one of the warnings:
        public static<T> T doIt(T input) {
            Object result = null;
            return (T) result; // Warning: Unnecessary cast to type T for expression of type Object
        }Can anybody explain why it doesn't like me casting to type T? I get a compiler error if I don't make the cast.
    Thanks.

    I think that the article is a bit of a red herring in this particular case. Whilst it's true that erasure means that the generic type information is lost at runtime, generic type information most certainly is not lost at compile time - that's the whole point of generics - to be typesafe at compile time.
    In this case, we clearly have an Object reference, which could refer to any object (though in this case it refers to null), and it's being assigned to a T reference, hence the need for an explicit downcast. Remove it and you get the following error
        Warning:  line (5) [unchecked] unchecked cast
                           found   : java.lang.Object
                           required: Twhich is as expected, and illustates the point that the case is clearly not 'unnecessary'.
    Regarding Eclipse, if you can't find out the command line arguments to javac try creating an Ant build script to do the compilation for you. The execution log of the script will tell you exactly what was passed to javac, and it's resulting output. Furthermore, since support for Java 5.0 in the development branch of Eclipse is currenty under active development, many problems such as this are bound to crop up. When you do run up against another problems again, you can use the Ant build script to determine whether or not the problem lies with Eclipse or the JDK. If it's Eclipse, you've a better chance of having the problem resolved throught the Eclipse forums and/or bug tracker.

  • Help with "unchecked conversion" warning

    Hello,
    following line
    Vector devices = SomeDeviceManager.getDeviceList();
    gives a warning (when compiled in java 1.5 with -Xlint):
    found raw type: java.util.Vector
    missing type parameters for generic class java.util.Vector<E>
    When I change code to
    Vector<DeviceInfo> devices = SomeDeviceManager.getDeviceList();
    warning turns into "unchecked conversion" warning. SomeDeviceManager is from some old .jar library, so it's not possible to change getDeviceList signature.
    How can I eliminate this warning?
    Thanks.

    @SuppressWarnings("unchecked")
    - Saish

  • WLC cert to avoid the security warning page

    Hi guys,
    I am doing some tests with installiing a 3rd party cert on a WLC to avoid the security warning page when trying to access the WLC through https, and I am following the following configuration example:
    http://www.cisco.com/en/US/tech/tk722/tk809/technologies_configuration_example09186a00806e367a.shtml
    I have followed the same precedures given in the above document, and I am using windows CA to sign the CSR just for a test, I could install the final .pem cert successfully onto the WLC however I am still getting the same warning page when I was trying to login to the WLC through https. I have checked in my certificate store and I have trusted the root CA which is the windows CA in this case.
    I have also tried to access the WLC from the CA server (windows 2008 box) still getting the same warning message.
    so what should I do in order to make this to work with windows CA? did I missed something in the configuration?
    Thanks in advance for your time and help.
    Andy

    ok guys.... I was wrong last time... actually after double check again it was NOT working .... I think i just simply trusted the cert last time when i was using firefox....
    I have tried a number of different things and double checked the places that mentioned previously in this thread however I could not pick up anything wrong in particular, although I know there must be something I have missed out.....
    so this time I have also read through some other references on the web, and found the following:
    http://www.my80211.com/home/2011/1/16/wlcgenerate-third-party-web-authentication-certificate-for-a.html
    I think I did very similar config and only difference is that I am using unchained cert.
    I have double checked the following:
    on virtual interface configuration, I have ip address 1.1.1.1 and DNS host name as "wlc2112.mydomain.local"
    from the controller GUI --> Security --> web auth --> certificate, under subject name, I have CN=wlc2112.mydomain.local, however under Issuer name, I have CN=mydomain, this is a bit different from the last screen shot in the above link. could this be a problem?
    in windows 2003 server, with DNS server I have a field called "wlc2112" with IP address 1.1.1.1
    as mentioned by Scott previously, I went to the mmc certificate snap in, and under trusted root certificate authorities, I have installed the WLC cert there and I could see it there as well.
    now if I try to access the WLC GUI from here I am still getting the error message same as the one below:
    http://www.vistaclues.com/the-security-certificate-presented-by-this-website-was-issues-for-a-different-website%E2%80%99s-address/
    I then followed the instruction and continue to the website, and when I go file --> properties --> certificate, it actually shows the certificate is issued to 169.254.1.1 and issued by 169.254.1.1, with a red cross on the cert itself....... I have no idea where is this come from, so I just want to ask when I try to access the WLC GUI through a web browser, after I type in https://wlc-ip-address, how does the browser know / search for which certificate it needs to look into? I think in my case here it clearly points to the wrong certificate?
    also on the server I went to http://127.0.0.1/certsrv and selected "download a CA certificate, certificate chain or CRL" and then "install this CA certificate chain", does this mean I acknowledge to trust the root CA by doing this?
    I am not sure what I have missed out but it just does not work for some reason... is there any other places that I need to check/verify?
    Sorry for the long writing but any comments would be highly appreciated.
    Thanks in advance for your help.

  • Is it possible to avoid duplicate material in Sale order creation

    Dear SD gurus
    Is it possible to avoid material duplication in va01 sale order creation. For amendment purpose the marketing user making new line item with amended qty instead of quantity change. kindly advise me to solve the problem.
    Thanks & Regards
    R.Udayakumar

    HI,
    There's no alternative to user disciplibe . Business reqt are sometimes like this only
    what you can do is use exit mv45afzz in saels order and put coding logic . this will surely work.
    {Removed by Moderator}
    regards
    Edited by: Lakshmipathi on Aug 29, 2009 6:13 PM

  • TA38633 is it possible to avoid having to do a "restore" entirely ? Also if i have to do a restore, i have windows 7- do i follow the steps for Windows XP?

    Regarding error 1601 - is it possible to avoid having to do a "restore" entirely ?
    Also if i have to do a restore, i have windows 7- do i follow the steps for Windows XP?
    Many thanks

    I'd refer to this
    http://support.apple.com/kb/TS3694 (talks about security software and this error)
    and this
    http://support.apple.com/kb/HT1414
    I've had Windows 7 for a while, but it seems the steps in iTunes are identical. 

  • Encore CS6 not possible to avoid transcoding

    Why does encore CS6 transcode some H.264 streams and some not? They are different sequences exported from the same project with the same settings out of premiere CS6. The parameters of all streams equal the settings in encore. But for some it is not possible to change the setting in encore to not transcode.

    Yes, I used H.264 Bluray 1440x1080 anamorph. I guess Encore ignored the anamorph flag for some files and transcoded them a second time to 1440x1080 - the result is a visible frame with a distorted 4:3 aspect ratio. I have found a resolution. I replaced the transcoded files in the encore transcode folder with copies of the original files and renamed them like the transcoded files: "original filename"_sessionFiles_Asf_session_1_video.m4v
    Perhaps its possible to avoid transcoding by simply placing renamed copies (in that name system above) of the original files in the transcode folder. I will try it in the future.

  • I use photoshop 6 (mac) if I subscribe to Premier CC do I have to subscribe to Photoshop CC also I want to use 6 as long as possible to avoid the subscriptions fees

    I use photoshop 6 (mac) if I subscribe to Premier CC do I have to subscribe to Photoshop CC also I want to use 6 as long as possible to avoid the subscriptions fees

    Completely separate products, so nothing to fear.
    Mylenium

  • Sql developer 3.0: could be possible to avoid creating connections

    Hi, when connecting from oracle forms, you don't have to create a connection, in the same way I don't know if could be possible to avoid creating connections when you are using a tnsnames.ora archive.
    simple to choose the connection as in oracle forms, and the posibility to save the password.
    thank you

    As stated in the forum announcement, you can request this at the SQL Developer Exchange, so other users can vote and add weight for possible future implementation.
    Regards,
    K.

Maybe you are looking for

  • Converting analog to dv

    I have a pinnacle movie box av adapter for my canon Hi8 camcorder. It has worked successfully for me in the past but recentley when I attempted to use it to capture footage in Imovie HD the computer never detected the camera attachment. I tried cycli

  • SQLException:refcursor value is invalid!What happened?

    my database is oracle 9i recently when I execute a sql query by JDBC Connection conn = getConnection(); stmt = conn.createStatement(); stmt.setQueryTimeout(20); String sqlText = "select * from table"; ResultSet res = stmt.execute(sqlText);often cause

  • Storing SUP credentials on Afaria Server

    Hi, I have a quick question to check if it is possible to read SUP credentials (CompanyIDsetting, activation code, URL prefix, UsernameSetting....) from Afaria server using a Afaria mobile device client. This would eliminate the need for the end-user

  • Process for material returns from Customer, mapped in CIN

    Hi Gurus, I have some queries (below) pertaining to CIN. 1. How is the Customer Materials returns is handled in CIN? What is the process flow (transactions)? Since, the goods are returned we can avail the excise duty paid earlier? So, is the RG23A Pa

  • Parsing Issue

    Greetings I have this string that is generated dynamically: Select top 10 destination, timeofexecution, accountID, lastfillquantity, client, ordernumber, symbol, buysell, orderMarking, lastfillprice, traderID from Trade with (NOLOCK) where ((traderID