Java RTTI - Run type type identification

This Question might seem odd; but its true:
In Java we have getClass() for an Object to know its REAL TYPE. But we dont have any method to get its CASTED TYPE class. Although, throughout code we know it at coding time; there might be cases where we want to know it programatically; (for creating inheritance relationships on the fly.)

I don't know why you would ever need this unless you were writing a compiler. If you keep a reference to an object, that reference is whatever the casted type is. i.e. void foo( MySubclass inSub, MySuperclass inSup )
    MySuperClass mySup = inSub; // can be done implicitly
    MySubClass mySub = (MySubClass)inSup; // legal, but can throw a ClassCastException
}and anywhere later in foo() the casted class is already known.
You might be able to use reflection to do more dynamic casts, but you still aren't going to keep a different reference....
I think maybe what you want in this case is something more like an interface where you know specific methods need to exist and you can override them...

Similar Messages

  • Java.io.StreamCorruptedException: Type code out of  range, is 63

    Hi,
    i ma using Weblogic 7.0 ......... I got one exception in the weblogic log, Exception is as follows -
    ####<Nov 28, 2006 3:15:54 PM EST> <Info> <EJB> <atnyprd5>
    <XXXServer1> <ExecuteThread: '83' for queue: 'default'> <kernel identity>
    <11864:d63651c3623375dd> <010051> <EJB Exception during invocation from home:
    [email protected]53 threw exception:
    com.xxxxxx.exception.XXXXXXEJBException: MSG: javax.naming.CommunicationException
    [Root exceptionis java.rmi.UnmarshalException: cannot unmarshaling return; nested  exception is:   1990         
    java.io.StreamCorruptedException: Type code out of  range, is 63]null TIME: 0> 1991
    com.xxxxxx.exception.xxxxxxEJBException: MSG: javax.naming.CommunicationException
    [Root exception is java.rmi.UnmarshalException: cannot  unmarshaling return; nested exception is:   1992
    java.io.StreamCorruptedException: Type code out of  range, is 63]null TIME: 0 1993
    at com.xxxxxx.util.EJBUtil.handleSysError (EJBUtil.java:40) 1994
    at com.xxxxxx.util.EJBUtil.handleSysError (EJBUtil.java:59) 1995
    at com.xxxxxx.db.DbAccess.initConnection (DbAccess.java:98) 1996
    at com.xxxxxx.db.DbAccess.<init>(DbAccess.java:37)
    I am getting this exception while fetching a datasource connection from the connection pool of weblogic.
    My applciation is running for past 2 years and we did not got this exception before, So I suspect there is no problem in the code......... where it is going wrong ????
    Please help me in this......
    Thanks and regards

    Hi,
    atleast any idea about what the exception is and what it is related to ???
    Its bit urjent to resolve
    Thankx and Regards

  • Java.io.StreamCorruptedException: Type code out of range, is -20

    Hi ,
    When i am connecting from a client to an EJB running in Weblogic on the localhost , I got the follwoing exception.
    GENERAL-EXCEPTION: java.rmi.UnmarshalException: failed to unmarshal cookie; nest
    ed exception is:
    java.io.StreamCorruptedException: Type code out of range, is -20
    java.rmi.UnmarshalException: failed to unmarshal cookie; nested exception is:
    java.io.StreamCorruptedException: Type code out of range, is -20
    java.io.StreamCorruptedException: Type code out of range, is -20
    at java.io.ObjectInputStream.peekCode(ObjectInputStream.java:1551)
    at java.io.ObjectInputStream.refill(ObjectInputStream.java:1679)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:278)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
    at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedO
    bjectInputStream.java:140)
    at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.ja
    va:91)
    at weblogic.rjvm.ResponseImpl.getReplicaInfo(ResponseImpl.java:171)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteR
    ef.java:264)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteR
    ef.java:229)
    Can anyone tell what this type code -20 is?

    www.google.com is your friend.
    http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=Type+code+out+of+range%2C+is+-20&btnG=Google+Search

  • MDO Query errors in log -[Cannot fetch column 22, which has JDBC type DOUBLE, into a Java variable of type ]

    Hello,
    We are seeing a lot of log messages like the one below when an MDO select query is run. There is a message for every numeric column. There doesnt seem to be any issue with the queries working properly its just creating a lot of log messages. Has anyone else had this issue?
    Exception of type com.sap.sql.log.OpenSQLException caught:
    Cannot fetch column 22, which has JDBC type DOUBLE, into a Java variable of type
    float..
    [EXCEPTION]
    com.sap.sql.log.OpenSQLException: Cannot fetch
    column 22, which has JDBC type DOUBLE, into a Java variable of type float.
    at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:83) ...

    Hi Christian,
    You are right. As in your case it is a select query it does not reflect the error automatically. In my case, I had an insert query so it failed then and there, which was easier to debug and fix.
    I have one question regarding your case. When you read the MDO using the query, what do you do with the output? Do you assign it to any local/transaction property in the output links of the query block or in a proceeding assignment block?
    Because, the error mentions that the assignment of float to double datatype fails. So, in theory there should be some assignment done with the output.
    Please check if you could figure out this part in your transaction.
    Regards,
    Saumya Govil

  • How do I get rid of the alert "(Java Scriprt Application)Type error: Text is undefined   I get it when I get a new Internet page using Firefow

    How do I get rid of the alert "(Java Scriprt Application)Type error: Text is undefined>  I get it when I get a new Internet page using Firefow

    I do not want to half to install things into my PC that i do not trust! I just want this gone and like i said Firefox should of given us the choice to add this and not forced us, because if there is no actual way to remove it then il be forced to remove Firefox till they either remove it or allow us to remove it!

  • Is there a forName() for java.lang.reflect.Type?

    Is there an equivelant to Class.forName() for all types?
    For example:forName("java.util.List<java.lang.Sring>");
    //or
    forName("int");Such a method would return a java.lang.reflect.Type, instead of return a java.lang.Class
    See also
    Field.getGenericType()
    Method.getGenericReturnType()

    incidentally, getGenericType() will give you the
    generic type of the member being examined, not the
    parameterized type.
    that is, if I declare a method like this:
    public <T extends MyInterface> T getStuff() {
    }I won't be able to reflectively find out what types
    of T are being used at runtime, only that it's of
    type 'T'. of limited use really
    Java's implementation of Generics isn't as good as it
    could be, mainly to maintain backwards compatibiityYou are right in that case because that is not a ParameterizedType that is a TypeVariable.
    Type can encompass both Types.

  • Java.util.Map type return in webservice method

    Wonder, how we can return a java.util.Map type from a webservice deployed on a
    weblogic 7.x environment..
    any input is appreciated.
    -Girish

    Thanks Michael. it helps.
    -Girish
    "Michael Wooten" <[email protected]> wrote:
    >
    Hi Girish,
    By definition, a Java object used as a input parameter (or return type)
    of a web
    service operation, must has a no-arg constructor in order for a Java-based
    Web
    Service Stack to serialize/deserialize it to/from XML. java.util.Map
    is an interface,
    so it does not meet this requirement :-)
    If your web service operation is just trying to return (or accept) a
    hash map
    of "arbitrary complex types", I recommend that you consider switching
    this to
    be an "array of arrays of specific complex types". The reason I say this
    is because,
    it allows even non-Java consumers to look at the <schema> elements in
    your web
    services' WSDL, and figure out all the possible "arbitrary complex types"
    that
    might be in this array. If you envision the consumer getting a box, where
    it can
    literally contain anything, you can probably see how much more code they
    would
    need to write, than if they knew the the box contained a box of these,
    and a box
    of these, and so on, and so on.
    Basically, all the "old school" type-safety rules still apply to web
    services
    computing. If you want web services with descent performance metrics,
    you're probably
    going to want to keep a lot of the "old school, distributed computing"
    practices
    in mind, when you design your stuff :-)
    That said, WLS 7.0 SP1 does not currently have a "built-in" HashMap codec.
    But,
    you could create one using the information at:
    http://edocs.bea.com/wls/docs70/webserv/customdata.html#1054435
    Regards,
    Mike Wooten
    "girish" <[email protected]> wrote:
    Wonder, how we can return a java.util.Map type from a webservice deployed
    on a
    weblogic 7.x environment..
    any input is appreciated.
    -Girish

  • Why java take enum type off

    why java take enum type off?
    When in switch statement, it become complex without enum type.
    Enum can constrained the range of integer value. Taking enum type off,
    method parameter checking will take lots effort.
    can any way to replace the functions of enum type.

    It was a disputable design decision.
    The original C "enum" type is however somewhat flawy from its lack of encapsulation (its elements "pollute the global namespace" - they are for this purpose!) and would not seamless fit into the typed, OO Java philosophy.
    Otherwise put, the original "C" enum fits well to the C philosophy but no to the C++ or Java one.

  • Failed to load value at index 22 with java object of type java.lang.String

    Hi all,
    As i am trying to open the notifications created from Administartor Workflow ,
    It throws a below error::
    oracle.apps.fnd.framework.OAException: oracle.jbo.AttributeLoadException: JBO-27022: Failed to load value at index 22 with java object of type java.lang.String due to java.sql.SQLException. at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:912) at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:886) at oracle.apps.fnd.framework.OAException.wrapperInvocationTargetException(OAException.java:1009) at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:211) at oracle.apps.fnd.framework.server.OAApplicationModuleImpl.invokeMethod(OAApplicationModuleImpl.java:720) at oracle.apps.ap.oie.workflow.apexp.webui.NotifExpLinesCO.processRequest(NotifExpLinesCO.java:116) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:600) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.process
    java.sql.SQLException: Invalid column index
    at oracle.jdbc.driver.OracleResultSetImpl.getObject(OracleResultSetImpl.java:1042) at oracle.jbo.server.OracleSQLBuilderImpl.doLoadFromResultSet(OracleSQLBuilderImpl.java:1198) at oracle.jbo.server.AttributeDefImpl.loadFromResultSet(AttributeDefImpl.java:1633) at oracle.jbo.server.ViewRowImpl.populate(ViewRowImpl.java:2221).
    No extensions done in the page
    Please let me know the cause for this error ASAP
    Thanks
    Kash

    Problem solved. set the datatype as timestamp for that attribute in buissiness object.

  • Java.io.StreamCorruptedException: Type code out of range, is 0, BLOB, Weblogic 7, Oracle 8i

    Test message

    Nagaraju wrote:
    Hi
    I am trying to insert a Java Object ( Serialized Bean) into Oracle BLOB. I am getting the following exception when reading back from Blob. Following is the code and the Exception stack is pasted below. I am using weblogic 7.0 Applcation server/Oracle 8.i
    If any body have an idea please let me know.
    Thanks is advance..
    Nagaraju.
    java.io.StreamCorruptedException: Type code out of range, is 0
    at java.io.ObjectInputStream.peekCode(ObjectInputStream.java:1551)
    at java.io.ObjectInputStream.refill(ObjectInputStream.java:1679)
    at java.io.ObjectInputStream.read(ObjectInputStream.java:1655)
    at java.io.DataInputStream.readInt(DataInputStream.java:333)
    at java.io.ObjectInputStream.readInt(ObjectInputStream.java:1975)
    at java.util.SimpleTimeZone.readObject(SimpleTimeZone.java:1437)Hi. Unless you post the whole stacktrace, or at least enough of it to show
    some weblogic or even jdbc classes, we can have no clue what this is about...
    Joe

  • What is java .jpr file type?

    What is java .jpr file type?

    jetq wrote:
    What is java .jpr file type?http://www.fileinfo.com/extension/jpr
    does that help?

  • JDOQL queryfilter failure while retrieving field of "java.lang.Object" Type.

    PROBLEM DESCRIPTION --->
    JDOQL FILTER ON A FIELD OF "java.lang.Object" TYPE, NOT WORKING.
    HELP REQUESTED WITH SUGGESTIONS OR POINTERS TO THE CORRECT SOLUTION.
    Deatiled Problem :=
    Environment :=
    Kodo version 2.4.1 (on Windows 2000).
    J2SDK 1.3.1_06 (on Windows 2000).
    Database:= MySQL 3.23.55 (on Windows 2000).
    Java Class Hierarchy Example:=
    SuperPersistentObject
    |__ LevelOneDescendant
    |__ LevelTwoDescendant
    |__ LastDescendant
    Procedures Followed :=
    Java class named "LastDescendant" is enhanced and persisted in the
    database.
    The field "m_value" is of java type "java.lang.Object" and is
    represented as a "blob" in the database.
    Aadequate data is pumped in the field "m_value" (Data of Type
    String/Integer/Double/Boolean etc.). The class "LastDescendant" is
    retrieved using following JDO specific code :=
    SUCCESSFUL EXAMPLE :=
    Extent extent= PersistentManager.getExtent
    (com.name.project.LastDescendant.class, false);
    String m_queryFilter = "";
    Query query = PersistentManager.getQuery(extent, m_queryFilter);
    Collection m_resultset = (Collection)query.execute();
    The above code returns all the available "LastDescendant" objects
    persisted in the DB. Post Load, The value in the field "m_value" of
    all the retrieved "LastDescendant" objects, is testeded successfully
    and found to be matching to the expected values.
    FAILED EXAMPLE :=
    Extent extent= PersistentManager.getExtent
    (com.name.project.LastDescendant.class, false);
    //Retrieving only the objects whose "m_value" field contains Integer
    // values, between 10 and 9000. (110 objects with Integer value
    // between 10 and 9000 are pumped in the DB, for testing).
    String m_queryFilter = "(m_value >= 10 && m_value <= 9000)";
    Query query = PersistentManager.getQuery(extent, m_queryFilter);
    Collection m_resultset = (Collection)query.execute();
    NO "LastDescendant" OBJECTS RETRIEVED, the Collection "m_resultset" is
    Empty, (Actually Expecting 110 objects).
    Tried every other way, using "declareImports()"/ "declareParameters()"/
    "declareVariables()" etc. Tried TypeCasting the m_value field to Integer,
    but to no avail.
    Actual Classes :=
    public class SuperPersistentObject implements java.io.Serializable {
    protected String appKey;
    public class LevelOneDescendant extends SuperPersistentObject {
    protected SuperPersistentObject m_classRef;
    public class LevelTwoDescendant extends LevelOneDescendant {
    protected Object m_value;
    public class LastDescendant extends LevelTwoDescendant {
    "project.jdo" meta-data entry :=
    <class name="SuperPersistentObject"
    identity-type="application"
    objectid-class="com.name.project.AppKeyImpl">
    <field name="appKey" primary-key="true"/>
    </class>
    <class name="LevelOneDescendant" identity-type="application"
    persistence-capable-superclass =
    "com.name.project.SuperPersistentObject">
    </class>
    <class name="LevelTwoDescendant" identity-type="application"
    persistence-capable-superclass =
    "com.name.project.LevelOneDescendant">
    <field name="m_value">
    <extension vendor-name="kodo" key="data-column" value="VALUE"/>
    </field>
    </class>
    <class name="LastDescendant" identity-type="application"
    persistence-capable-superclass="com.name.project.LevelTwoDescendant">
    </class>
    JDO related properties :=
    javax.jdo.PersistenceManagerFactoryClass =
    com.solarmetric.kodo.impl.jdbc.JDBCPersistenceManagerFactory
    javax.jdo.option.ConnectionURL= jdbc:mysql://localhost/PRTestDB
    javax.jdo.option.ConnectionUserName= SuperUser
    javax.jdo.option.ConnectionPassword= <xxxxxx>
    javax.jdo.option.ConnectionDriverName= com.mysql.jdbc.Driver
    javax.jdo.option.Optimistic= true
    javax.jdo.option.RetainValues= true
    javax.jdo.option.NontransactionalRead= true
    javax.jdo.option.NontransactionalWrite= true
    javax.jdo.option.RestoreValues= true
    javax.jdo.option.Multithreaded= true
    javax.jdo.option.MsWait= 5000
    javax.jdo.option.IgnoreCache= false
    javax.jdo.option.MinPool= 1
    javax.jdo.option.MaxPool= 80
    com.solarmetric.kodo.impl.jdbc.WarnOnPersistentTypeFailure= true
    com.solarmetric.kodo.impl.jdbc.SequenceFactoryClass=
    com.solarmetric.kodo.impl.jdbc.schema.DBSequenceFactory
    com.solarmetric.kodo.impl.jdbc.FlatInheritanceMapping= true
    com.solarmetric.kodo.LicenseKey= <xxxx-yyyy-zzzz-2345-6789>
    com.solarmetric.kodo.EnableQueryExtensions= false
    com.solarmetric.kodo.DefaultFetchThreshold= 30
    com.solarmetric.kodo.DefaultFetchBatchSize= 10

    You can't query on a blob column.

  • Verify EJB after Cannot determine the Java EE module type for

    Hi All,
    I start verify EJB it's throw an exception
    Which cases occurring this exception, how can I resolve this?
    Could not verify successfully.
    java.io.IOException: Cannot determine the Java EE module type for C:\Mystuff\projects\Naki\Naki-ejb\dist\Naki-ejb.jar
         at com.sun.enterprise.deployment.archivist.PluggableArchivistsHelper.getArchivistForArchive(PluggableArchivistsHelper.java:137)
         at com.sun.enterprise.deployment.archivist.PluggableArchivistsHelper.getArchivistForArchive(PluggableArchivistsHelper.java:98)
         at com.sun.enterprise.deployment.archivist.PluggableArchivistsHelper.getArchivistForArchive(PluggableArchivistsHelper.java:110)
         at com.sun.enterprise.deployment.archivist.ArchivistFactory.getArchivistForArchive(ArchivistFactory.java:93)
         at com.sun.enterprise.tools.verifier.VerificationHandler.initStandalone(VerificationHandler.java:204)
         at com.sun.enterprise.tools.verifier.VerificationHandler.<init>(VerificationHandler.java:109)
         at com.sun.enterprise.tools.verifier.Verifier.verify(Verifier.java:140)
         at com.sun.enterprise.tools.verifier.Verifier.main(Verifier.java:114)
    Thanks,

    I'm getting the same error although i'm not receiving those entries in the log. Can someone please respond to this post. I've tried a lot of things but can't seem to figure it out. Please email me at [email protected] if you can help.
    Thanks

  • Prime LMS jobs default run type

    Is there a way to change the default run type for LMS jobs from "immediate" to something else? Reason I want to do this is because default "immediate" is always checked and it is always above where you type job description and your email address and if you don't change it the job will run immediately. We have had incidents where people executed Netconfig jobs during production hours by overlooking the default option and caused network interruption. If someone know a way or may be Joe Clarke can chime in.

    Hi Nawas,
    There is no option to change the default run type of the jobs in LMS.
    However, for NetConfig jobs, you can enable the "Approver list" feature so that someone in your team must give the OK before any config change jobs can be triggered.
    This may help out preventing these jobs triggered during working hours to the production network.
    Further info on the setup can be found here:
    http://www.cisco.com/en/US/docs/net_mgmt/ciscoworks_lan_management_solution/4.2/user/guide/admin/jobs.html#wpmkr1143683
    http://www.cisco.com/en/US/docs/net_mgmt/ciscoworks_lan_management_solution/4.2/user/guide/admin/jobs.html#wp1143752
    Regards,
    Luis

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

Maybe you are looking for