Is down casting possible in Java objects(reference variables)?

I hope, Java up casting and down casting is possible in Java primitive variables like int float and so on.
My doubt is,Does in object of Java(reference variables) support down casting?

makpandian wrote:
the ques i asked here is popped from my mind.We know that.
But i did not get answer .Because you didn't do any research.
Than s why i ask this here..That's the wrong approach. Do some research first. Use google, a textbook, a tutorial, the JLS, write some code, etc. etc.
After spending time and effort doing that, if you still have questions, indicate clearly what you read and what part you didn't understand. The way you're doing it is NOT an effective way to learn, and it's a waste of everyone's time.

Similar Messages

  • Error : Access not possible using "null" objects reference

    Hello.
    i am working with a zbapi.
    i called a external email program in this bapi,everything is working fine over here.
    In webdynpro java they mapped my bapi and starting working from there.
    every functionality is working fine but regarding this email stuff it is showing an error as access not possible using null objects reference.
    where could be the possible error.
    is it in webdynpro or in abap side.

    Raghu,
    You are right. When it comes from the WD Java, may be you are not passing any value at all. You can trace it by these ways.
    1. Check it using SE37, make sure everyhting is fine.
    2. Print all the values that you are passing to the RFC in the execute RFC method().
    3. using ST05 transaction in R/3, enable RFC and SQL trace, check what is passing in between web dynpro and R/3.
    Moreover paste your error message here.
    Thanks,
    Raj.

  • Why Java provides Object cloning even if there is Object reference variable

    In both cases original value get changed. What is the difference between these (clonable interface & Object reference variable)

    Cloneable is a way to make a copy of an object, so that you now have two objects, usually with the same state. Assigning the value in one reference variable to another variable (I can only assume that's what you're talking about, as your question is not clear at all) does not create another object.

  • How to create a local object reference variable in teststand sequence file programatically using C#

    I want to create a local object reference variable in a TestStand sequence file programatically using C#.

    Hi,
    Accoring to your reply in this Thread
    http://forums.ni.com/ni/board/message?board.id=330&thread.id=26984
    Just try this example. There you will create a numeric variable during excuting a sequence!
    Hope this is what you are looking for. 
    Please attach all your questions here.
    juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=
    Attachments:
    CTestStandDialog.zip ‏31 KB

  • Java object reference index..

    Hi All,
    I have two doubts, it will be great if I could be suggested any thing on these.
    1. Is it a good idea to create an java object in the memory, may be 1-2 Mb in size and keep it in the server for a long period? The reason is the server restart may be once in 50-60 days.
    2. If the component objects(child objects... you can think of the whole object as a XML file structure), of the above mentioned object, are having a unique attribute id (type String), can I genereate an index on this attribute that will give me the reference of the object, so that I do not have to traverse the entire object to get an child object having a unique id.
    Can you suggest any algorithm (number of child objects / items in the index will be 80000 - 100000) like binary indexing or hash function etc..
    where in I will search the index with an unique ID (String type) and get a Object reference.
    TIA
    Ayusman

    1. Is it a good idea to ...Based on the information you gave, it is impossible to access whether it is a good idea or bad idea. If your computer has infinite CPU and infinite memory, then it wouldn't matter if you kept 1-2 MB in memory. It comes down to 1) how much time would it take to load that information from disk 2) how much time is the end user / process that depends on the information willing to wait 3) what other resources would be competing for that memory 4) how often would that memory be accessed, in other words, what is the gain / loss of not having it in memory vs the gain / loss of having it in memory.
    2. If the component objects(child objects... A hashtable would provide one possible solution. If your tree structure is likely to grow into 10s or 100s of MBs, then you may want to use a database. XML in my opinion is more of a transitional state of storing information (e.g. when the information needs to be transfered). I don't think storing a XML tree in memory is a good idea because it may not lend well to writing code to gather information.

  • Java Object References

    Is there any way to find out whether any java object has any active reference or not, means is it referenced till now or ready for gc. If it possible then can we get the information that from where is it referenced?

    Are you trying to write a garbage collector?
    The basic problem here is if you're analyzing an object to see if it's being linked to, that means that you must have an active link (unless you're outside of the application)

  • Inhiterance:unknow down-cast exception.Access a private attrib.from subclas

    Hi guys,
    I need your help.
    Many examples, shows that i can create a sub-class inheriting from a super-class, add methods and attributes, make something like : <subclass variable> ?= <superclass instance> and then call method of the subclass (that are able to access to protect data of superclass instance for example).
    But when i try to do the same with a class derived from cl_gui_alv_grid, i have always a casting type exception in the down-cast instruction.
    Example :
    field-symbols: <outtab> type standard table.
    data : gos_alv type ref to cl_gui_alv_grid.
    *       CLASS lcl_gui_alv_grid DEFINITION
    class lcl_gui_alv_grid definition inheriting from cl_gui_alv_grid.
      public section.
        methods : get_tab_line.
    endclass.                    "lcl_gui_alv_grid DEFINITION
    *       CLASS lcl_gui_alv_grid IMPLEMENTATION
    class lcl_gui_alv_grid implementation.
      method get_tab_line.
    * mt_outtab is the data table held as a protected attribute
    * in class cl_gui_alv_grid.
        assign me->mt_outtab->* to <outtab>. "Original data
      endmethod.                    "get_tab_line
    endclass.                    "lcl_gui_alv_grid IMPLEMENTATION
    data : l_alv type ref to lcl_gui_alv_grid.
    But when i do a downcast like this (gos_alv was already created with "create object" istruction):
    l_alv ?= gos_alv.
    I have an exception of casting error. I cannot understand why and how to solve the problem.
    Thank you very much for your collaboration.
    Andrea

    Hi Andrea,
    I suggest you to tweak a code a litte bit as I guess the point is to get mt_outtab table, right?
    CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
      PUBLIC SECTION.
        CLASS-METHODS get_tab_line IMPORTING o_alv TYPE REF TO cl_gui_alv_grid.    "declare method as static one
    ENDCLASS.                   
    CLASS lcl_gui_alv_grid IMPLEMENTATION.
      METHOD get_tab_line.
        FIELD-SYMBOLS <outtab> TYPE STANDARD TABLE.
        assign me->mt_outtab->* to <outtab>.
        "your desired coding here
      ENDMETHOD.                   
    ENDCLASS.                   
    Now all you need to do is to call static method get_tab_line providing your actual alv reference
    data : gos_alv type ref to cl_gui_alv_grid.
    CREATE OBJECT gos_alv ....
    lcl_gui_alv_grid=>get_tab_line( gos_alv ).     
    As for your question, why this code
    l_alv ?= gos_alv.
    triggeres an exception cx_sy_move_cast_error .
    If you use this coding
      TRY.
          l_alv ?= gos_alv.
        CATCH.
          cx_sy_move_cast_error
    "system will end up here
      ENDTRY.
    ...you would prevent the system to dump out, but the exception will be triggered anyway. You will just catch it.
    The problem arises simply from fact that down cast checks wheterer these two reference variables l_alv and gos_alv are on the same level. This is why you put there question mark ? asking the system if gos_alv in fact contains appropriate reference. You can only evaluate it during program execution.
    When it comes to down cast always image such situation.
    You have VEHICLE class (your cl_gui_alv_grid ). The class which inherits from it is PLANE (your lcl_gui_alv_grid). Now you can always do such assingnment
    VEHICLE = PLANE (cl_gui_alv_grid = lcl_gui_alv_grid)    "up cast - narrow cast
    but you never can do this
    PLANE = VEHICLE (lcl_gui_alv_grid = cl_gui_alv_grid)  "down cast
    It is becasue plane is always a vehicle, but vehicle doesn't have to be a plain. It can be either a truck, ship or a plane.
    Therefore for down cast you always has to ask system if VEHICLE really contains (during exection) reference to a PLANE. That's why you write it like
    PLANE ?= VEHICLE (lcl_gui_alv_grid ?= cl_gui_alv_grid)
    The system checks then if vehicle really contains plane reference inside.
    Thought it might be not useful for first sight, it is a basis of polimorphism, but it is a talk for another time;)
    Regards
    Marcin

  • Object casting: confusion in ABAP Objects: Complete Reference book

    Hi,
    During Object Assignments using casting, is a Type Test carried out during the syntax check or at runtime?
    A.5.2.2 (page 1008) of 'ABAP Objects: The Complete Reference' says about Widening Cast: "...you must check at runtime...". However on the next page under A.5.3.2 it says of Widening Cast in Data References: "The syntax check precludes...".
    A.5.4 (page 1010) concerns Assignments between Object Reference Variables, but makes no mention of whether checks are carried out by a syntax check or at runtime.
    Also nowhere does it mention when Type Tests for Narrow casting takes place. Can anyone clear my confusion please? Unfortunatly I don't know enough about this stuff to test by writing some code.
    Thanks.

    William,
    Your questions can be answered by the following rule for object references, which I found in the book "ABAP Objects" by Horst Keller and Sascha Krüger:
    "... that the static type of the target variable must be equal to or more general than the dynamic type of the source variable."
    Here "static type" means the type with which an object reference variable is declared. "Dynamic type" is the type that the object reference variable has at runtime. The dynamic type of an object reference is always more special than its static type, otherwise a runtime error occurs.
    With this rule all your questions can be answered:
    1. The Narrowing Cast is always checked during the syntax check. Example:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref1 = o_ref2.  
    Here the reference o_ref2 has a dynamic type "class_1" or a subclass of it, which is narrower than its static type "class_1", which is narrower than the static type "object" of the reference o_ref1. Therefore, the syntax check says that the assignment is OK.
    2. The Widening Cast is always checked at runtime and requires an assignment using the operator ?=. If you use the operator = in the assignment, a syntax error occurs. Therefore the following  example produces a syntax error (try it yourself):
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 = o_ref1.  
    The correction for this syntax error is:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 ?= o_ref1.
    Now the syntax check is satified, and the correctness of the widening cast is checked at runtime.
    Kind regards,
    Michael Kraemer
    Message was edited by: Michael Kraemer

  • Cast error in java sound

    Hey, i got a little run-time error:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.sun.media.sound.PortMixer$PortMixerPort
    the code segment it occurs at is here:
    case 0:
          targetDataLine1 = (TargetDataLine)mixer1.getLine(targetInfo);
          targetDataLine2 = targetDataLine1;
    }Some background info: I used getTargetLines() method of Mixer to obtain an arraylist of all the Line.Info objects (for targetLines) in a mixer, then I passed this into a GUI class, and made a vector to display in combo box. once user selects an item, it casts it back into Line.Info, and calls the mixer's "getLine()" method to retrieve the line. But I get the cast error. I know you can cast from Line to TargetDataLine (since TargetDataLine is a subinterface of Line) -- and I saw it on a tutorial, so I don't know what's wrong. Any help?
    If you need more info, just tell me.

    But still, the tutorial I looked at
    (http://java.sun.com/j2se/1.5.0/docs/guide/sound/progr
    ammer_guide/chapter3.html#113154)
    still showed it down-casting from a Line object to a
    TargetDataLine object.
    You need to understand the difference between a reference and an object. The object itself was a TargetDataLine object, otherwise the cast wouldn't have worked. The reference to it was of type Line.
    // obj is a reference of type Object. The object it points to is a String:
    Object obj = "I am a String";
    // Which explains why this works:
    String s = (String)obj;
    // and why this fails:
    Integer i = (Integer)obj;
    Not to mention, the java API says that the
    getLine(Line.Info) object returns an object of type
    Line.
    And I still don't understand why you can't cast from
    a superclass to a subclass. I know intuitively, it
    makes since, since not all RECTANGLES are SQAURES,
    but all SQUARES are RECTANGLES. But still, I know
    enough programming to remember numerous instances of
    casting Object as other classes....
    See above.
    Oh, and what does the $ symbol in
    com.sun.media.sound.PortMixer$PortMixerPort mean?It means that the the class PortMixerPort is an inner class (or nested class, I never remember the difference :-) in the class PortMixer.

  • A simple teststand applicatio​n passing object reference to C#

    Hi,
     I have a  .NET application written in C# which has a UI with  NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit controls. This UI is invoked by a custom step in TestStand. One of the values, entered by user in the UI is a object reference variable created in a previous step. I need to store the values entered in the UI during the edit mode of the step, into the TestStand Step variables. And during the run mode i use these values to execute the logic in C#. 
    The problem is during edit time, the object reference variable, entered in the UI, has no value. It is null. So there is no use storing it at edit time. During the runtime i am trying to retrieve the value of the object reference variable using GetValInterface(...) and GetValIDispatch(..) methods of PropertyObject. But the object returned to C# is of type System.__COMObject wherease in TestStand that object reference is of type .NET.
    I don't know how a .NET object reference is converted to COM object when it is returned to .Net function.
    Also is there any other method to send this object reference variable's (whose value is '.NET' in previous step itself) value to .NET as a .NET object only so that i can typecast to appropriate type and start using.
    Thanks.
    Please let me know if anything is not clear.
    I have attached the .Net project, .ini file for the custom step and a example sequence file.
    Attachments:
    CCustomStepObj.zip ‏23 KB

    Hello Shivapriya,
    The example you've sent doesn't compile. And it without it I'm affraid I do not understand the problem you're describing.
    You've given references to libraries that you've not attached with your files.
    For the C# I see these are the
    IADCore.dll
    InstrimentInterfaces.dll
    TestStand also seems to want to reach for the assembly named TestSystem.dll.
    I can only tell you that I have used successfully in the past the Variables in TestStand to hold .NET object references, and call methods on them and I experienced nothing similar that you describe, but I don't quite follow what is the problem here, as I can't use the example. 
    I would appriciate if you cold narrow down the example to 1 dll or something where the problem occurs and than resend it.
    Regards,
    Maciej 
    Message Edited by Mac671 on 09-28-2009 02:59 AM

  • Serialization of Object reference

    Hi,
    I'd like to serialize (or store in some way) a reference I have on
    an Object. This reference is coming from a stateful bean, so it's
    an Object instance and not serializable. The idea is to be able to
    retreive the reference on the bean after a failure of the client.
    Thanks for your help.
    --MA                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    If the reference is not serializable then what you can do is
    override writeobject() and readObject() method. I the write object write down information regarding that reference(it depends on your application). Stateful bean construct details.
    In readObject() read those details and get a reference to it through JNDI and set that reference to your object reference variable.
    This is Custom Serialization.

  • Debug object references

    I have a reference to a .net list.
    Is it possible to "debug the content" of the list during runtime ? i.e. can i somehow "expand the view" to see properties ?
     

    One way would be to use .NET action steps to get the values into local variables. You can use mscorlib as the assembly and call Array.GetValue to get the individual values from the array then use another .NET step with your assembly and the USB_SA.Peak data type with each element to get properties, fields, or call methods on that type. There are other ways too, such as if the type USB_SA.Peak is really a struct (i.e. value type), then you can create an equivalent TestStand custom data type for it and have the .NET adapter do the data conversion for you to get the values into a local variable that is an array of that type rather than using an Object Reference variable. It really depends on what you are doing and how your .NET types are defined.
    Hope this helps,
    -Doug

  • Bug in Java objects not serializable

    I plan to use the latest version TopLink 10.1.3.1.0 with Oracle Database 10g (10.2.x).
    Do I still have to use the “Type Conversion” mapping as I had to do in order to address the reported non-serializable bug exiting in TopLink (9.0.4.5). See the link for the bug description:
    http://www.oracle.com/technology/documentation/1012_solaris/relnotes.1012/relnotes/toplink.htm#CEGEBDEG
    My Java object instance variable is defined as java.sql.Timestamp and the corresponding data type on the Oracle DB is defined as TIMESTAMP(6). Can I use the direct-to-field mapping from now on with new TopLink 10.1.3.1.0 without the serializable issue? If I still have to use the Type Conversion mapping, please help provide some detail about the mapping.
    Many thanks for any help.

    From what I can understand from your reply, I can use the direct-to-field mapping for Java class attribute of java.sql.Timestamp to the Oracle DB 10.2.x data type of TIMESTAMP(6) without any issue of not serializable. Please confirm. Many thanks!
    By the way, I am having the same issue (Java objects not serializable) with Oracle DB 10.1.x when I use the direct-to-field mapping. It seems to me that this is more than the Oracle 9i JDBC driver.
    If I have to do this with TopLink 10.1.3.1.0 + Oracle 10.2.x, I plan to use the Type Conversion with:
    Java class attribute: java.sql.Timestamp
    DB data type: oracle.sql.TIMESTAMP
    Is this the proper way to do it? Please confirm.

  • To pass parameter values to the object reference of action step in sequence file of teststand programatically using C#.

    //Initialize the Engine
                EngineClass myEngine = new EngineClass();
                myEngine.LoadTypePaletteFilesEx(TypeConflictHandlerTypes.ConflictHandler_Prompt, 0);
                Step myStep = myEngine.NewStep(AdapterKeyNames.DotNetAdapterKeyname,StepTypes.StepType_Action);
                myStep.Name = "object";
                DotNetModule dotnetmodule = myStep.Module as DotNetModule;
                dotnetmodule.SetAssembly(DotNetModuleAssemblyLocations.DotNetModule_AssemblyLocation_File,@"C:sequence.dll");
                dotnetmodule.ClassName = "CN";
                dotnetmodule.MemberType = DotNetModuleMemberTypes.DotNetMember_GetProperty;
                dotnetmodule.MemberName = "ISI";  
    mySequence.Locals.NewSubProperty("object", PropertyValueTypes.PropValType_Reference, false, "", 0);        
    Sequence mySequence = myEngine.NewSequence();
                mySequence.Locals.NewSubProperty(varName, PropertyValueTypes.PropValType_Reference, false, String.Empty, 0);
    mySequence.InsertStep(myStep, 0, StepGroups.StepGroup_Main);
                SequenceFile seqFile = myEngine.NewSequenceFile();
                seqFile.InsertSequence(mySequence);
    seqFile.Save("C:\\mySeq.seq");
    I have done this,dynamically creating a sequence file in teststand programatically through c#.
    Problem is
    1.I created an action step and object Reference variable for the step, but i am not able to pass  parameter values to the objectReference 
    2.I am not able to load the sequence in to the main Sequence of the sequence file in the teststand. How can I do these two things.

    Hi,
    have you ever followed on my Links ?!?!?
    If not please jump to this one
    http://forums.ni.com/ni/board/message?board.id=330&thread.id=26880 
    and read the the answer from Mannoch
    starting with this words:
    Anthony -
    Currently, functionality for retrieving the Metadata Token for a class constructor or member is not fully provided in the TestStand .NET Adapter API. The DotNetModule.GetConstructorMetadataToken() and DotNetModule.GetMetadataToken() methods only return the correct Metadata Token when the member/constructor prototypes have already been loaded. Thus, in the case of your code, when you call DotNetModule.GetMetadataToken(), the method is returning -1 because the member prototype for the Step you are referring to has not yet been loaded.
    That means have to do a workaround for your stuff.
    Juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=

  • Any Resources for Learning Object Reference in TestStand?

    Hi All,
    I have been using Active X servers in TestStand for several years and now some of the newer stuff I am being supplied with is Dot Net objects. Does anyone know of somewhere to learn the correct way to use object references in TestStand. I don't understand when you should create a new object  vs just using an existing object reference. I also would like to understand how to use an object reference variable.
    I looked at the TS examples, but there is not an explanation. 
    Any ideas?
    TIA,
    Jim

    Jim,
    You may try reading through the NI TestStand Advanced Architecture Series, specifically Chapter 2: Using the NI TestStand Object Model. These may shed some light on the issue.
    Regards,
    Steven Zittrower
    Applications Engineer
    National Instruments
    http://www.ni.com

Maybe you are looking for

  • Word to Pages 09

    I have alot of Word documents on a pendrive. I plugged in into my Macbook Pro and was amazed when they opened up in Pages 09 (Iwork retail v9.0.3) . But there is one problem some of the text is displayed in the wrong direction. I can't seem to find a

  • How will the Macbook do in the long run ?

    I will be buying a new Macbook when Leopard and iLife 07 are released. However, I have been increasingly hearing and reading negative feedback about the Intel GMA950 in the Macbook, so I've been looking to stretch my budget and get the low end 15" Ma

  • AVCHD presets in CS5 where? + Settings...

    Am I being dumb, or do I need to load them from somehwere I have no AVCHD preset in the sequence or general tab when I create a new project ( in sequence I have DV24, DV NTSC, DV pal, DVC pro 50HD, Mobile and devices) Finding it hard to find resource

  • Trial download of Acrobat XI Pro fails

    I try to download a trial of Acrobat XI Pro. It starts downloading CS6 - over and over. Then it decides to try Elements 13. Then I decide to accept the CS6 downloads. It is an incomplete download, even though it claims to be "complete." I am using Fi

  • Contradiction: SEQUENCE and AUTO_INCREMENT

    Most recommendations tell: You have to use SEQUENCE instead of an auto_increment column. In contradiction to this I found the following AUTO INCREMENT feature in Oracle® Database Lite SQL Reference 10g (10.2.0): 4.3.18 CREATE TABLE auto increment