Generics and warning free code

Is it possible to cast to a generic class without compiler warnings?
        Object object = null;
        Comparable comparable1 = (Comparable) object;
        comparable1.compareTo(object); // warning: unchecked call
        Comparable<Object> comparable2 = (Comparable<Object>) object; // warning: unchecked cast
        comparable2.compareTo(object);
        String s = (String) object; // ok
        s.compareTo((String) object); // okMy problem is that casts like these are perfectly useful java code and have nothing to do with interacting with legacy code! Yet it seems no longer possible to write such code without warnings!
Ruud Diterwich
(ps. sorry for the cross post)

No, it is not "legacy code", unless you claim that
any explicit cast is "legacy code". (which would be
an assumption that I strongly disagreed with...)
The compiler feels compelled to issue a warning in
this case solely because Generics are not first-class
Java types and thus not subject to runtime
typechecking at the point of the cast.No, I wouldn't claim all casts are legacy code, and my characterization of the whole example as such was hasty.
I take your point about precisely why the explict cast to (Comparable<Object>) produces a warning. There's no avoiding this without producing a solution that doesn't involve erasure, and I don't think we want to go over that again?
Comparable has been parameterized in 5.0 and as such using it as a raw type and calling compareTo() is now coding in a legacy style that produces warnings. Casting doesn't even need to come into it:
        Comparable comparable1 =  "";       
        comparable1.compareTo(null);  //warning: [unchecked] unckeched callYou can argue they should have introduced a Comparable2 interface and left the original alone, but that's another tradeoff.

Similar Messages

  • Why do i need to enter the credit card information for downloading free apps and redeem the codes?

    getting a message says apple id has not yet been used with the itunes store while trying to download apps
    why do i need to enter the credit card information for downloading free apps and redeem the codes?

    As a security precaution, Apple verifies your billing credentials with every transaction whether paid or free apps or using the balance of a redeemed code.

  • I'm trying to update my application and it is asking me to change my billing account it is not accepting the security code. I am not trying to buy an application just to update and install free apps

    I'm trying to update my application and it is asking me to change my billing account it is not accepting the security code. I am not trying to buy an application just to update and install free apps

    So why are you posting on this forum?  We're users here, not Apple.  Click the "Contact Us" link in the lower right hand corner of this page.

  • Trying to download free photoshop and received error code 148:3 can you help

    Need help tying to download free photoshop and receiving error code 148:3

    Something is preventing the licensing from working. Make sure to run with sufficient user privileges and file permissions.
    Mylenium

  • TS1814 I can't seem to get the drivers downloaded on my windows laptop for my iphone 5s, the info is coming up generic and im getting a code 1.  Please help

    I can't seem to get the drivers downloaded on my windows laptop for my iphone 5s, the info is coming up generic and im getting a code 1.  Please help

    All necessary drivers are included in the iTunes install package.
    Please clarify exactly what the problem is.
    the info is coming up generic and im getting a code 1
    That's not very informative.

  • HT3702 My Payment Method That Is On Fill Is Correct And My Security Code Is Correct You All Are Telling Me That It Is Invaild And I Can Not Download No Free Apps From The Apps Store!!!!!!!!

    My Payment Method That Is On Fill Is Correct And My Security Code Is Correct You All Are Telling Me That It Is Invaild And I Can Not Download No Free Apps From The Apps Store!!!!!!!!

    The short answer is no.
    Unless you are selling the app via the Enterprise Deployment option, everyone has to download via their own iTunes account ID. Yes, iTunes can be used by multiple IDs but this makes it very messy to resolve later.
    What kind of app is this? Which Expo? If an Expo for selling apps has poor Internet connection I would question the validity of using such an expo in the first place.

  • Hi, after installing Adobe CC I tried opening Adobe Photoshop. This failed. I get the opening window where it says installing plugins searching etc, after which PS opens in full screen. Just moments after that there's a fail warning, no code number, only

    Hi, after installing Adobe CC I tried opening Adobe Photoshop. This failed.
    I get the opening window where it says installing plugins searching etc, after which PS opens in full screen.
    Just moments after that there's a failure warning, no code number, only the warning that PS failed to open and PS will close.
    I tried downloading it for a second time, but this did'nt solve the problem.
    Befor the CC version I used a one year student version of Adobe CS6.
    What can I do?

    Regarding the Flash Player problem, disable Hardware Acceleration to circumvent driver incompatibilities.
    Regarding the Flash Pro installation problems, post in the Flash forums or http://forums.adobe.com/community/download_install_setup

  • Error: There was a failure to call cluster code from a provider. Exception message: Generic failure . Status code: 5015. SQL 2012 SP1

    Hi,
    Please help. I was trying to remove a SQL 2012 SP1 two node clustered instance using setup (Mantenance -> Remove Node)
    I started by doing this on passive node (and was successful) but when I ran setup on active node just before finishing successfully I got this error:
    TITLE: Microsoft SQL Server 2012 Service Pack 1 Setup
    The following error has occurred:
    The resource 'BCK_SG1DB' could not be moved from cluster group 'SQL Server (SG1DB)' to cluster group 'Available Storage'. 
    Error: There was a failure to call cluster code from a provider. Exception message: Generic failure . Status code: 5015.
    Description: The operation failed because either the specified cluster node is not the owner of the resource, or the node
    is not a possible owner of the resource.
    For help, click:
    http://go.microsoft.com/fwlink?LinkID=20476&ProdName=Microsoft%20SQL%20Server&EvtSrc=setup.rll&EvtID=50000&ProdVer=11.0.3000.0&EvtType=0xE8049925%25400x42B4DED7
    BUTTONS:
    OK
    I noticed that SG1DB instance was removed on both nodes but on Failover Cluster Manager -> Services and Applications the SQL server instance for SG1DB is still there. So I tried to delete it but got the error:
    Failed to delete SQL Server SG1DB. An error was encountered while deleting the cluster service or
    application SQL Server SG1DB. Could not move the resource to available storage. An error occured
    while moving the resource BCK_SG1DB to the clustered service or application Available Storage
    Any ideas why it failed or how could I delete the SQL server instance from Clauster?
    Thx

    Hello,
    Please read the following resource.
    https://support.microsoft.com/en-us/kb/kbview/313882?wa=wsignin1.0
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Casting, generics and unchecked expressions

    Hi
    I'm trying to access a vector of Recommendations held by a Person object, but I don't want to allow direct access to the vector, just the information contained in it
    public Vector<Recommendation> getRecommendations() {
         return((Vector<Recommendation>)recList.clone());
    }The trouble I'm having is that I have to cast the recList.clone() as a Vector<Recommendation> to return a compatible type.
    When I do this, the source compiles with a warning: unchecked cast.
    Could someone explain an unchecked cast and give me a pointer to solving this please? I've not managed to find anything about combining generics and clones in my books. Is there another way of returning a copy of the vector? All I want to do is make the objects in the vector available for viewing, via processing in a servlet, to a jsp.
    Thanks in advance

    YoGee wrote:
    What you are exposing is a Vector with a reference to a clone of the internal data array, you are not cloning the elements in that data array. So basically if you modify an element in one Vector chances are it will be reflected in the other (assuming the element is mutable).Thanks for the reply.
    I should have said that what I want to achieve is:
    make the Vector<Recommendation>recList contents available for viewing, but not expose the objects so that they are able to be changed - so what I have done is not good!
    after some thought, what I really want is this:
    If what you actually want to achieve is a deep clone (i.e. clone the elements in the internal data array) you need to do it yourself by looping through the Vector and cloning each element in it (assuming the elements implement clone properly)so thanks for the help!

  • Regarding error and warning messages in log.

    hi all,
    i need to move the error meaasges and warning messages to log....am downloading the FI data from EC...
    my req is if the company code  is not in header..throws warning message" comp has not been for header" and at the same the file has to be generated.....
    and for line item if the trading partner is not present it throws error message and at the same time file has to be generated.....
    for exxample like this.....
    GL account     FS item      Trading Partner  TC     Value in TC       LC       Value in LC
    12345678          213344   XXXX            USD     1,000          1,000
         USD

    Hi,
    u can use an internla table and get all the Logs,
    for Example if company code is not there the move the company code and pernr to ITAB1,
    if EMP subgroup is not there in header then move to ITAB2.and at the final appene itab1,itab2 to one more inernal table so that this final table contains all the errored pernrs, and u can display it

  • Lock and wait free data structures...???

    Hi - I am developing an application that requires multi-threading. We are testing this on CentOS 5, 64 BIT, running on Intel Quad Core machines, with 8 GB RAM (3 of them). I am using a III party tool to create a datagrid, and have 2 more machines in the federation to monitor performance.
    Java collections/synchronized collections has restriction on multithreading. If thread1 performs puts or removes objects in collection (Tree, Map, List, Set), thread2 cannot iterate. Thread2 can iterate only if it acquires synchronized lock on collection – this implies thread1 has to wait till iteration is over. This introduces latency. If without acquiring lock thread2 does iteration, then “concurrent modification thread exception” arises.
    For real time application like financial markets (multiple thread based application) every microsecond/millisecond matters.
    For workaround at present we have customized sun code by masking “modCount and expectedCount”. This means check for concurrent modification is disabled. But not quite sure this is correct approach. Other option was multiple buffering.
    Other option is lock and waits free data structures – which I am interested.
    Any ideas on this???
    cheers - Murali

    It depends on what is acceptable to you.
    If you are only iterating and not removing any objects through the iterator, then there are two concerns;
    1. Iterator skips some elements.
    2. Iterator iterates to non-existent elements causing NPE.
    You can also copy the datastructure. Then iterate over the copy.
    You can also do "copy on write." This causes a copy only when the datastructure is modified and those iterators already created are not affected. This is the technique I use.
    Eliminating locks is not the objective. Locking is very quick. Its the contention that you want to eliminate. COW can do this nicely in my experience. Depends on your requirements.
    P.S. Try assigning duke dollars to the question and you will probably get more viewers.

  • Window Errors and Warning in this Transaction not shown

    We're using Designer 6.5.82.3.0.
    Business rules aren't generated according to CDM Ruleframe, no CAPI. But Table API/trigger logic.
    => Pre-Before-Insert-Row
    BEGIN
    if CDR_CPN.F_CPN_UNIQUE(:new.CODE)
    then
    -- a new code
    null;
    else
    -- code already exists
    QMS$ERRORS.SHOW_MESSAGE
    ('CDR-05000'
    ,:new.CODE);
    end if;
    END;
    When an business rule fails the window Errors and Warning in this Transaction with the error-message is not shown. Instead we get the message Transaction failed
    (when using sqlplus the same message appears, then running @messages.sql =>correct message)
    According to a previous discussion the ON-ERROR of the module component should be modified (author Bart van Ges 22 May 2002). And this works, the window Errors and Warning in this Transaction is shown with the correct message.
    Has anyone another solution, patch or any idea why the window doesn't appear without the modification?
    Cheers,
    Bob

    All,
    Since Headstart for 6.0 (patch 12) and Headstart for 6i, Headstart default only functions well in combination with CDM RuleFrame. If you want to deviate from this standard, the functionality in the libraries should be adapted for this purpose. There are several ways to do this:
    - show serverside errors in an error Alert window
    - show serverside errors in the RuleFrame transaction and errors window.
    Whatever approach you choose - in this thread several suggestions are being made - it is not documented in headstart how to do this. The Oracle Headstart group is not able at this moment to investigate time to workout the alternatives, though I will add an enhancement request to headstart to document these options in the headstart user guide.
    Two extra suggestions:
    - try to test your workaround as well as possible (try to raise errors from server, client, try to violate server constraints (pk, uk, fk, ck) and try to let serverside pl/sql fail.
    - if you do not make use of ruleframe, you might run into a problem if you try to commit in the serverside logic, in this case remove the calls in the template package (qms$even_form) to open and close the transaction (pre-commit and post-forms-commit trigger events).
    Regards,
    Marc Vah[i]Long postings are being truncated to ~1 kB at this time.

  • Race free code?

    I recently saw a reference to the term "race free code", but I've been unable to get a good description of what it means. The more perceptive amongst you will be able to guess my question by now... so why are elephants greyish? (And while answering that, could someone also explain what "race free" means.)

    Imagine you have an instance variable called count:
    ++count;
    System.out.println(count); If multiple threads run this code then you have a potential race condition. I.e. thread 1 increments the count to 1 but before it calls println thread 2 increments the count again to 2. The result is that both threads print 2.
    To make the code "race free" you could synchronize it:
    synchronized(this) {
      tempCount = ++count;
    System.out.println(tempCount); Now thread 1 will correctly print 1 and thread 2 will print 2.

  • PM's regarding free codes

    I recently received a PM through this forum's PM system offering me free codes or some such scam, but I can't see any simple way to report the mesage, or the user... I know it's somewhat frowned upon to name and shame so I'm avoiding that for now...

    A report fuction is certainly needed for private messaging just pop in the forum feedback topic and mention it.http://community.eu.playstation.com/t5/PlayStation-Off-Topic/Forum-Feedback-amp-Community-Suggestions/td-p/23297524 The more that request this feature the better,it may get implemented in the forum quicker.

  • Running and restricting unsafe code within a safe application

    My application (actually a web application) will do the following:
    - Obtain Java source code from an untrusted source. One such piece of source code will be a JUnit test class (and another will be the class(es) it is testing).
    - Compile the source code in memory, storing the compiled classes into byte[] arrays, using the JSR-199 compiler.
    - Load the JUnit test class that was just compiled, using a URLClassLoader.
    - Run the JUnit test (using the JUnitCore core class in JUnit 4.4) and report the results to the client.
    Since the source code is untrusted, it may do malicious things that I want to prevent. I have wide flexibility in limiting the permissions of the code; for example, I can disallow file reading and writing, network access, etc. However, I do not want to restrict these permissions on my own application, or the JUnit code itself (such as the class JUnitCore, which runs the JUnit test). So the flow will go like this:
    1. Allow unrestricted security policy initially.
    2. Obtain source code.
    3. Compile source code.
    4. Apply restricted security policy.
    5. Load compiled classes and use JUnitCore to run the JUnit test class. (Loading should be restricted so that static initializers in the unsafe code cannot do harm.)
    6. Remove restricted security policy.
    7. Report results (in particular, violating the security policy means, "Test failed").
    However, my very basic understanding of the security policies in Java is that permission granting within a call stack seems to go the other way; untrusted code is run with a restricted security policy, but it may make a call to a system library, for instance, that runs as a privileged block and has extra permissions that the unsafe calling code does not have. I want to flip that around and say, "My code is okay, but when it executes the method JUnitCore.run, restrict the access of that method". Or, to be even more fine-grained, "My code, and any code from junit-4.4.jar such as JUnitCore, is okay, but somewhere in the bowels of JUnitCore.run, some unsafe code will eventually be called, and I want its access restricted."
    I don't even know if this is possible the way I have stated it, and if so, I am having trouble mapping the abstract concepts of a codebase, code signers, etc., on to the specific pieces of code in my project. Someone on another forum suggested that the URLClassLoader used to load the unsafe classes would somehow play the role of a codebase, so that I could state that anything loaded with that class loader should be restricted, but I have not seen a syntax for expressing this in the documentation. Plus, I don't see how using the URLClassLoader used to load the unsafe classes would play a role, since permissions are granted, not denied. It seems that I need a way to map a codebase to the safe code, not the unsafe code, and then grant permissions to the unsafe code.
    It seems like it could be as simple as creating a policy file (say, unsafe.policy) with the contents
    grant codebase "My Application + supporting classes I wrote + any class in junit-4.4.jar" {
        permission java.security.AllPermission;
    };and running java -Djava.security.manager -Djava.security.policy=unsafe.policy MyApp, except that I don't really know how to specify the codebase, or if it is possible to draw a box around my code + junit-4.4.jar in that way.
    Thank you,
    Dave
    Edited by: pexatus on Aug 10, 2008 12:48 PM

    >
    Have a look at AccessController and AccessControlContext. These are the tools you need for this task.
    >
    By "this task", do you mean, "writing a custom SecurityManager"? Or do you mean the more general task of creating a security policy (such as by writing a policy file) to ensure untrusted code does no damage?
    I'm sorry to be so slow, but I don't see how to use the two classes you mention for my task. I assume that the only reason I need AccessController is to call AccessController.getContext() to get an instance of AccessControlContext, since the other methods of AccessController don't seem to be what I need. AccessController.checkPermission presumes I have successfully written the security policy already, which is the problem I am trying to solve, and the various AccessController.doPrivileged methods appear to grant extra privileges to code that is called, which is the problem I mentioned earlier: I want certain code that I call to have fewer privileges, rather than more.
    Similarly, I do not see any methods in AccessControlContext that could tell me whether the current executing code is trusted or not. It, too, has a checkPermission method that will work if I set up the security policy correct, which is what I cannot figure out how to do in the first place, and a getDomainCombiner() method. A DomainCombiner has only a single method, which assumes that I already have an array of ProtectionDomain objects. To create a ProtectionDomain, I need to specify a CodeSource, which is, as the documentation indicates, an extension of "the concept of a codebase". It is at this point I get completely lost in the abstract and generic nouns such as domain, codebase, code source, context, and I do not see how to connect them to concrete nouns that I understand such as class file, package, method, etc. Is it the case that I need to create a CodeSource representing the trusted classes? Is there an elegant way to create a CodeSource representing all the classes in a a project (say, under a given directory, or contained within a given jar file), short of enumerating them or digging into directories and jar files doing a search? And once I create this CodeSource within my program, what do I do with it to specify that I want my security policy to allow all permissions for the classes represented by the CodeSource, and restricted permissions for all classes outside the CodeSource, regardless of call order? (since trusted code will call untrusted code, and I do not want the permissions of the trusted code to be inherited by the untrusted code)
    Again, I am sorry to be so ignorant, and I appreciate the help, but I am simply having trouble connecting the concepts described in the documentation to the specific concrete aspects of my application.
    Dave

Maybe you are looking for

  • How can I use the RMS.vi over more than one period?

    Hi everyone, I am using the Cycle average and RMS.VI to get the RMS value of a alternative voltage (2kHz). To acquire this signal I am using a differentiel AI of a 6225 card (at 250kS/s) and the RMS value is correct, it works fine. However from what

  • Customization of iBOT in OBIEE 11g

    I need to automatically subscribe reports into iBOTs in the following scenarios (1)     When the result reaches the threshold limit ( will be configured for each report) (2)     Will provide button for subscription of the report Can you please explai

  • One hard drive's full, I want to add another........

    i have my library on an external hard drive and it will soon be full. i want to know if i can add a new hard drive and have new content go the the new drive while still leaving the current content on the old drive? can itunes pull files from more tha

  • Older MacPro as an External Hard Drive

    Greetings I recently moved from my 2010 MacPro to an iMac. Since the MacPro has 4 hard drive bays I was thinking of using the MacPro as an "external" hard drive. I can access the drives thru my ethernet network but I was wondering if there is a more

  • Sales order Price change while releasing the credit block using VKM3

    Hi, Please advice me on the following issue I am facing: I am creating a sales order, which is having automatic pricing. The price is getting picked up using the condition records correctly in the order. The pricing condition can be manually changed