Type safety issue

Hi All,
Running the below code, works fine. but my expectation says the code in setobject method should throw Class CastException.
But this is not happening.
Is this a bug in jdk6. The type inintially defined as Integer afterwards converts into String.
public class Test<T> {
     private T value;
     public static void main(String[] args) {
          Test<Integer> test = new Test<Integer>();
          test.setObject("Test");
     private void setObject(Object obj) {
          try {
               value = (T)obj;
               System.out.println(value);
          } catch (ClassCastException castException) {
               castException.printStackTrace();
}

s_adi_bilaye wrote:
There is indeed a run-time type safety check at the cast operationIf there is an downcast from Object to the specific <T> in this case <Integer> then there needs to be an exception which is raised if there is a runtime type safety check.
When we dont use generics we get the runtime type safety check and a class cast exception is thrown.
Since no exception is raised at the cast line I understand that when we use generics there is no type safety check at the runtime for the "generic object". This explanation is also aligned with the generics documentation.
This is not quite correct. Your code would throw ClassCastExceptions due to compiler-generated casts if there were any.
You are declaring a List of Integers. Then you deliberately cheat the type-checks by using the "raw" type List to insert a String into the List.
So far, so good: no exception because of the cheating.
But after that, you never access the list's elements in a way that warrant a compiler-generated cast!
This line:
System.out.println(list.get(i));uses the overload PrintStream.println(Object).
Thus, the smart compiler decides that there is no need to first cast the list element to Integer and then immediately back to Object!
You can double-check by changing the line to:
System.out.println(list.get(i).intValue());Now the overload PrintStream.println(int) will be used, triggering the necessary cast to Integer, which will then throw a ClassCastException.

Similar Messages

  • MacBook Pro Health and safety issue: Potential Burn during normal use

    Hi,
    I am not a complainer. I worked for Apple of 6+ years and have had a top of the line Apple Notebook since Apple created the concept of the laptop notebook.
    I recently experienced a 3rd degree burn using my MacBook Pro that I think Apple needs to warn folks about:
    MacBook Pro 17"
    Machine Model: MacBookPro1,2
    CPU Type: Intel Core Duo
    Number Of Cores: 2
    CPU Speed: 2.16 GHz
    L2 Cache (shared): 2 MB
    Memory: 2 GB
    Bus Speed: 667 MHz
    Boot ROM Version: MBP12.0061.B00
    Serial Number: ()
    SMC Version: 1.5f10
    Sudden Motion Sensor:
    State: Enabled
    I had my laptop on my lap. I was wearing shorts. It noticed that it was warm on my leg where the left side of the MacBook Pro was touching my leg, but it didn't create a reflex pain response.
    Upon completing my session, when I closed the machine and put it away, I noticed a 1 inch x .75 inch blister on my leg where it had been touching the MacBook/Pro; and it has turn out to be a significant burn.
    I checked all the documentaiton that came with my MacBook Pro and there was no warning about the potential of this situation.
    I recommend that Apple let owners know, perhaps through an email or a popup when they visit the Apple site. Lastly, when I encountered this issue, I wasn't running any high performance, compute bound applications. It was email. So, I have to believe that it is possible to detect wait states within the processes running and take the processors to a low power mode of operation when they are not performing actual work. Am I out in left field here?
    I want Apple to be successful. I haven't heard of a similar complaint on any of the high performance PC's at work. Beyond a Health and Safety issue, this is also a reputation issue. Better to face into the storm and honestly deal with this issue.
    A slightly crisp, but loyal, MacBook Pro user.
    Mike Doherty
    MacBook Pro Mac OS X (10.4.5) Potential Health and Safety Issue- 3rd degreee burn potential under normal use

    Mike... I do sympathize with your situation but let me correct you:
    I recently experienced a 3rd degree burn using my
    MacBook Pro
    Do you know what a 3rd degree burn is? A 3rd degree burn involves the dermis, and is full thickness involving the subcutaneous tissues and fat underneath your skin layers. This is something that usually happens when man meets fire, electrocution, and chemical burns. A 3rd degree burn is not typically achieved by a simple transfer of energy by conduction, unless extreme heat for an extended period of time.
    I had my laptop on my lap. I was wearing shorts. It
    noticed that it was warm on my leg where the left
    side of the MacBook Pro was touching my leg, but it
    didn't create a reflex pain response.
    Reflex pain response? Don't try to make up medical terminology. You didn't feel it much like you don't feel the sun when you get a sunburn initially... your skin slowly adjusted to the temperature, and at some point the heat increased over the threshold of which causes damage. You should have gone to the doctor if you were overly concerned.
    Upon completing my session, when I closed the machine
    and put it away, I noticed a 1 inch x .75 inch
    blister on my leg where it had been touching the
    MacBook/Pro; and it has turn out to be a significant
    burn.
    You're right, if you have a 1inch by almost 1 inch heat related blister on your leg, it is bad, nothing that I would consider significant. That is less then 1% of your body, probably about 0.25% to 0.5%, and only a 2nd degree burn. Your most significant complication would be a local skin infection.
    I checked all the documentaiton that came with my
    MacBook Pro and there was no warning about the
    potential of this situation.
    Actually... I'd hate to call you a liar, but I'm pretty sure that it does warn about burns.
    To confirm this, apple has also information online:
    http://docs.info.apple.com/article.html?artnum=30612
    I recommend that Apple let owners know, perhaps
    through an email or a popup when they visit the Apple
    site.
    They do... link above.
    Lastly, when I encountered this issue, I wasn't
    running any high performance, compute bound
    applications. It was email. So, I have to believe
    that it is possible to detect wait states within the
    processes running and take the processors to a low
    power mode of operation when they are not performing
    actual work. Am I out in left field here?
    No, you're definitely not. Here's where I start to agree with you. For the computer to heat up that much, when not doing things like rendering video is abnormal, and you deserve to have apple check out your computer. I think you should contact them on this concern.
    I want Apple to be successful. I haven't heard of a
    similar complaint on any of the high performance PC's
    at work. Beyond a Health and Safety issue, this is
    also a reputation issue. Better to face into the
    storm and honestly deal with this issue.
    It's harder for other manufacturers... our computers are aluminum, designed to disperse the heat. Technically they are considered "portables" not laptops, but I don't get into that argument because I disagree with the word "portable"... it's meant to work on your lap, and if you can't comfortably using regular apps, you deserve an answer.
    A slightly crisp, but loyal, MacBook Pro user.
    Hey, at least you're taking it with some humor. It's a shame you had to get hurt as a result of your computer. If I were you I would have gone to your Primary Care Physician, documented the burn, and returned your computer for a new one, and for something say, a free iPod for your pain.
    Sorry you got hurt, I think you should have your heat issue professionally investigated through apple care

  • How to handle type safety when using com.sap.typeservices.IProposalList

    Hi,
    I have been testing out the new features in Web Dynpro Java CE EHP1 using a scenario with BPM and SAP MDM. One of the new features I tested is the Ajax feature of using suggestion values. I have an InputField UI element which have bound to a context attribute (CountriesView/Country) which is of type string. The UI element has the "suggestValues" value set to true. I then use the IProposalList to produce a valueset. This will make the InputField UI appear as a combo box and allow the users to type in a few characters and utilize the Ajax framework to automatically search in the list of values.
    The following code works perfectly ok but I don't understand how I should handle the compiler warning "IProposalList is a raw type. References to generic type IProposalList<T> should be parameterized"?
    IProposalList proposalsCountry = wdContext.nodeCountriesView().getNodeInfo().getAttribute(IPrivateComp1.ICountriesViewElement.COUNTRY).getModifiableSimpleType().getSVServices().getProposals();
    for(int i=0;i<bua.length;i++){
        IPrivateComp1.ICountriesViewElement buaelement=wdContext.createCountriesViewElement();
        buaelement.setCountry(bua<i>[0]);
        buaelement.setCode(bua<i>[1]);
        bualist.add(buaelement);
        proposalsCountry.add(bua<i>[0]);
    wdContext.nodeCountriesView().bind(bualist);
    I don't have any issues handling this for other types such as ArrayList. Using the syntax "IProposalList<String> proposalsCountry ...." will handle the "proposalsCountry.add .." part but I still have a warning "Type safety: The expression of type IProposalList needs unchecked conversion to conform to IProposalList<String>"
    Any ideas on how to handle this?
    Thanks,
    Johan

    Hi,
    Eventhough there are no replies to this thread I thought I should update with what I belive is an answer to my question. Excerpt from http://stackoverflow.com/questions/382/what-is-the-meaning-of-the-type-safety-warning-in-certain-java-generics-casts:
    "This warning is there because Java is not actually storing type information at runtime in an object that uses generics. Thus, if 'object' is actually a List<String>, there will be no ClassCastException at runtime except until an item is accessed from the list that doesn't match the generic type defined in the variable. This can cause further complications if items are added to the list with this incorrect generic type information. Any code still holding a reference to the list but with the correct generic type information will now have an inconsistent list. To remove the warning, try:
    List<?> list = (List<?>) object;However, note that you will not be able to use certain methods such as add because the compiler doesn't know if you are trying to add an object of incorrect type. The above will work in a lot of situations, but if you have to use add or some similarly restricted method, you will just have to suffer the yellow underline in Eclipse (or a SuppressWarning annotation)."
    The last line explain the reason for my issue and the lack of a solution when using add method.
    /Johan

  • New tabs vanish when I view another one, MOST URL's vanish after a second and that is a safety issue if you can see if you are on the right page!

    A while ( couple weeks ) before the last update and change I noticed my URL's were vanishing a second after I arrived on a page. Not all URL's but most. This is a safety issue if I can't see I'm on the right page and have not been diverted.
    ALSO, I can't copy them to send a link via email if they aren't there! I found a way in the old FF click down list, but even that feature is gone on this new version! This needs fixed at once.
    AND when I make a new tab it vanishes! Or worse does not display like a tab. I can't go back and forth between pages if the tab vanishes. This started with the last FF update and change. This is poor design!!! When I updated the restore previous session grayed out. All my tabs were gone and I don't have them all in history. I was researching some things and it was important, now I can't remember them all. This is not a good thing!
    Unless you pin all your tabs immediately they will vanish??????? Stupid design. It does not even show the new tab for THIS page!!! "but is does show your URL....hmmmmm"
    What is the reason for having an arrow go through open tabs if they vanish???
    PLEASE FIX THIS or I'll have to change browsers, I'll have no choice. How can you do anything if FF erases your URL's or tabs!

    Hey Fox1User,
    Thank you for your message. I believe that this will happen when you have a dark theme applied to the new version of Firefox. It has been resolved in the 29.0.1 update that went out yesterday and would love to hear if this has improved the issue for you. I understand that the tabs are disappearing and it sounds like they may be blending into the tab bar.
    However! if this is not the case, can you please show a screenshot of the tabs [[How do I create a screenshot of my problem?]] after trying to produce this in Safe Mode [[Troubleshoot Firefox issues using Safe Mode]].
    I hope we find the culprit, looking forward to your reply.
    I also noticed you have 4 versions of Flash installed.

  • I have updated my ipad yestarday sicne then i am not able to open any application on my ipad2. some of the application able to open in the page and not able to open all the applications in the second page. Does any one got this type of issue? any sugg?

    i have updated my ipad yestarday sicne then i am not able to open any application on my ipad2. some of the application able to open in the page and not able to open all the applications in the second page. Does any one got this type of issue? any suggestions?

    This problem has been reported a few times. The solution is to install any new App say a free one. This seems to fix whatever has gone wrong.

  • Thread Safety Issue with DOM

    I am parsing an XML into a DOM object using the Xerces parser that is packaged with JDK 1.5.
    First, I create a new instance of the DocumentBuilderFactory and then using the factory, create a new DocumentBuilder. I then parse the XML using the DocumentBuilder to obtain a DOM object.
    Somehow, I am seeing the same DOM object being used for different XMLs.
    Is there a thread safety issue with the Xerces parser?

    certainly, Xerces parser is not thread safe. You have to provide thread safety by making sure that only one thread is allowed to access DocumentBuilder object.

  • Type casting issue

    Hello All,
    I've a Type casting issue. Could yu please help me resolving it.
    I'm trying to initialize the variable v with sysdate ('mon-dd-yy:hh:mi:ss') but couldn't initialize. I was able to do that in the body but is it not possible to do it in the declaration part?
    I was able to do like this
    DECLARE
      v varchar2(25);
    BEGIN
      SELECT to_char(sysdate,'mon-dd-yy:hh:mi:ss') INTO v FROM dual;
      DBMS_OUTPUT.PUT_LINE(v);
    END;
    Output looks like this: jan-19-12:04:32:11But how to do it in delaration part?
    DECLARE
      v varchar2(25);
      v := to_date(sysdate, 'mon-dd-...') ? ? ?
    BEGIN
        DBMS_OUTPUT.PUT_LINE(v);
    END;Thx
    Shank.

    You don't need to cast a sysdate to a date. It already is a date.
    SQL> alter session set nls_date_format = 'mon-dd-yy:hh:mi:ss';
    Session altered.
    SQL>
    SQL> DECLARE
      2    v varchar2(25);
      3    v_date date:= sysdate;
      4  BEGIN
      5      DBMS_OUTPUT.PUT_LINE(v_date);
      6  END;
      7  /
    jan-19-12:04:46:40
    PL/SQL procedure successfully completed.Hope this helps.

  • Creating output type for issuing print

    hello friends
                           can anybody tell me the process or steps to create output type to issue print

    HI.
    Goto NACE transaction.
    Select the application for whch you want to create the output type. For ex. select v3 for invoice.
    Click on 'Output Types' button on application toolbar.
    Click on 'New Entries'.
    Click on Processing Routines on the left-side to enter the driver program and SAPscript/Smartform name.
    Regards.
    Jay

  • How do I gain type safety with a generic method taking a class object?

    How do I achieve type safety with the following code without getting a compile error?
    import java.util.ArrayList;
    import java.util.List;
    public class Main {
        public static void main(String[] args) throws Exception {
            ListenerHolder th = new ListenerHolder();
            List<TestObject<String>> list = createTestObjectList();
            /* *** compiler error here *** */
            th.addListener(TestObject.class, list);
        private final static List<TestObject<String>> createTestObjectList() {
            List<TestObject<String>> list = new ArrayList<TestObject<String>>();
            return list;
        private final static class ListenerHolder {
                /* *** my generic method *** */
                public <T> void addListener(Class<T> listenerType, List<T> listener) { }
        private final static class TestObject<T> { }
    }The compiler error is:
    C:\java\Main.java:11: <T>addListener(java.lang.Class<T>,java.util.List<T>) in Main.ListenerHolder cannot be applied to (java.lang.Class<Main.TestObject>,java.util.List<Main.TestObject<java.lang.String>>)
    Thanks in advance,
    Dan

    dandubois wrote:
    Thanks for the help, that is exactly what I wanted to know.
    It didn't occur to me that TestObject<T> would in some respects be considered as an 'extends' of TestObject as I know the compiler converts them all back to plain TestObjects.Maybe I should have written TestObject<?>, to make it more obvious. There's some supertype/subtype relation diagram in the Generics FAQ somewhere, if you need more detailed information.
    In the end, I think jtahlborn's solution might be more appropriate in the described scenario, so you should go for it.

  • Upgrade to 12c database, what type of issues were reported

    We are thinking about upgrade to 12c database. Would like to find out what type of issues were reported after database from 11g to 12c. We want to prepare any possible issues that might happen.
    Thanks everyone for your inputs.

    I believe your database version is 11.2.0.2.0, since it is the minimum required version for 12c.
    You can apply latest PSU patch to 12c oracle home which has many bug fixes for 12c.
    In case your environment is a critical production system and you can perform testings to judge how the performance will be after upgrade.
    For that you can make use of "Real Application Testing" concept which is called as Database replay
    It works as below
    1) We will be creating test database instance having same configuration as production (hardware, resource)
    2) Invoke database replay capture activity at source database, it will start capturing database metrics. Perform necessary operations which should be tested in upgraded instance. For example, Load tests, EOD operation (Performance issue will create more impact to these tests)
    Capture mechanism will record necessary details and stores it in source database server. We will be notified about the location.
    Capture activity's overhead is very less. It will not impact normal db operations.
    3)  Once testing is over move the captured results to test machine
    4) Upgrade test instance to 11.2.0.3 version (in our case)
    5) Invoke database reply to apply the captured tests (production) to test instance.
    6) Execute replay reports that will give good comparison details on Performance, Data variation, etc
    Data variation gives comparison between query results in source and test instance.
    Thanks,
    Krishna

  • Type mismatch issue

    1) create package spec with two record type. Note : 1 attribute common in both the types
    CREATE OR REPLACE PACKAGE gfstm_parm_test AS
    TYPE g_rec_1 IS RECORD
    (ship_type_flag varchar2(1),
    reason_code_flag varchar2(1)
    TYPE g_rec_2 IS RECORD
    (ship_type_flag varchar2(1),
    cost_by_supplier_flag varchar2(1)
    end gfstm_parm_test ;
    2) create procedure with one of the record type. i.e g_rec_1
    create or replace procedure test_rec_type_pr(i_rec_var IN gfstm_parm_test.g_rec_1) is
    begin
    dbms_output.put_line(i_rec_var.ship_type_flag);
    end;
    3) execute the below block for g_rec_1 by calling procedure test_rec_type_pr
    ans: works
    Requirement: The same procedure WITHOUT ANY MODIFICATION to be used for the other type g_rec_2 as input parameter and should print 'a'. But getting type mismatch issues.
    How to make it to work ?
    declare
    l_rec_1 gfstm_parm_test.g_rec_1;
    l_rec_2 gfstm_parm_test.g_rec_2;
    begin
    l_rec_2.ship_type_flag := 'a';
    test_rec_type_pr(l_rec_2);
    end;
    Thanks,
    Vinodh

    Seems you'll have to uncomment something (as Solomon says, types are not defined to be intermixed at will)
    declare
    l_rec_1 gfstm_parm_test.g_rec_1;
    l_rec_2 gfstm_parm_test.g_rec_2;
    begin
      l_rec_2.ship_type_flag := 'a';
      l_rec_1.ship_type_flag := l_rec_2.ship_type_flag;
      l_rec_1.reason_code_flag := ''  -- or whatever ...
      test_rec_type_pr(l_rec_1);
    end;Regards
    Etbin

  • Type safety violation with generics

    how the following line violates type saftey in generics.plz help
    Gen<Integer> gens[] = new Gen<Integer>[10];

    how the following line violates type safety in generics.It doesn't.

  • When setting up my apple id for the apple store I get to the credit card screen and it tells me I have to contact support to finish.  I can't seem to contact support as there is no number for them on this type of issue.

    When setting up my apple id for the apple store I get to the credit card screen and it tells me I have to contact support to finish.  I can't seem to contact support as there is no number for them on this type of issue.  How the **** to I talk to a person who can fix this?

    It's a real problem when you're deployed outside the US and your billing address, though totally correct, is not. This seems to be a common complaint. I think the billing address vs. your present location causes some security concern or similar nonsense that prevents progress.
    The only way I know of to resolve this is to contact iTunes Support by email. I have never had to wait more than a day for a response:
    http://www.apple.com/emea/support/itunes/contact.html
    The response should not be "automated'. Explain your circumstances. You deserve a personalized response.

  • In the appstore where to buy software , called input on safety issues always pop !

    In the appstore where to buy software , called input on safety issues always pop !

    After defining the questions an answers an giving an extra email-address the popups disappear. It's for extra safety.

  • Do u need to run broadband disc safety issue

    Hi,
        When I first went with BT engineer set it all up, since then I have a new computer, I have never run the BT set up disc on it, read some where I should, as it would cause a safety issue, can anyone tell me if this is correct, as I know others that just pick up from the hub, without having run the disc. clarry.
    Solved!
    Go to Solution.

    Hi arron1719,
    Well the disk contains Destop Help which can come in pretty handy.  I am not sure how old your disk is but it possible that Desktop Help has been updated since it was sent.
    If you want to get the software you can still download it from our website:
    http://bt.custhelp.com/app/answers/detail/a_id/12941/c/346
    Thx
    Craig
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)”
    td-p/30">Ratings star on the left-hand side of the post.
    If someone answers your question correctly please let other members know by clicking on ’Mark as Accepted Solution’.

Maybe you are looking for

  • Link User Management ABAP-Java Stack

    Hello everybody, we have a WAS 6.40 ABAP+Java running. In client '000' if i create a new user, this user is also available at the java stack of the WAS. But if i create a new user in client 'XXX' (a copy of the client '001') it does not show up at th

  • Problem with ORACLE_SID

    I am not able startup a database in nomount state for particular ORACLE_SID. It seems it doesn't like the ORACLE_SID I set to. It's throwing following error ORA-07345: The datafile name must not contain the string '..'. Steps I did like follows 1) ex

  • How do I tune and watch TV (IVTV) ?

    I have a Hauppauge WinTV PVR-150 and have installed ivtv-utils. I'm assuming the card gets detected correctly. dmesg | grep ivtv ivtv: Start initialization, version 1.0.0 ivtv0: Initializing card #0 ivtv0: Autodetected Hauppauge card (cx23416 based)

  • Scan default settings in preview

    Nearly every time, I scan with preview with the same settings. But I don't find a possibility to save my settings as default. Is there no way in no program of the Mac OS (preview, digital images, system settings of printers/scanners)? Thanks for help

  • XI...infrastructure

    can any let me know ur suggestions on the following things a) To be able to understand the application requirements b) To understand the current mode of communication between SAP and other systems c) analysing the load on the XI infrastrucutre curren