Reflection and generics

Hi all:
I am working with the generic and reflection stuff. Well the problem is that in one of my clases I have a data
private Vector<nAryNode<T>> childs;
.....where nAryNode<T> is a class I created using generics.
Now when I want to initialize my childs variable, well the easy thing to do is:
childs = new Vector<nAryNode<T>>(3)But I want to initialize it using reflection and my code is:
        Class v = Class.forName("java.util.Vector");
        Class[] argVector = new Class[] {int.class};
        Constructor consVector = v.getConstructor(argVector);
        Object[] arguments = new Object[] {new Integer(n)};
        childs = (Vector<nAryNode<T>>)consVector.newInstance(arguments);Finally when I compile I got the annoying warning message
nAryNode.java:29: warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.Vector<nAryNode<T>>
childs = (Vector<nAryNode<T>>)consVector.newInstance(arguments);
^
Well my program can run, but I would like to make disappear that message. Please if you have any suggestions for me, it will be great. Thx

AFAIK, there is no solution to this currently because arrays of generic types are not allowed. Therefore "consVector.newInstance(arguments);" return a Vector and cannot be made to return "Vector<Integer>" (or whatever)

Similar Messages

  • Reflection and Generic Collections

    Hi -
    I'm having trouble with reflection on Sets
    I have a set of type T extends U and want to return the class of T:
    public static <T extends U> Class<T> getSetType(Set<T> set) {
    // what to do?
    }Any help?
    Message was edited by:
    [email protected]

    parameterized types are not present at runtime, as danny basically indicated. what you want to do here is neither a generics nor a reflection issue: unless the Set is empty, you can just examine the first object it contains for it's class:
    public static <T extends U> Class<T> getSetType(Set<T> set) {
         if ( null == set ) {
            return null;
         if ( 0 == set.size() ) {
            return null;
         return set.iterator().next().getClass();
    }

  • Problem in generic value copier class / reflection and generic classes

    Hello experts,
    I try to archive the following and am struggling for quite some time now. Can someone please give an assessment if this is possible:
    I am trying to write a generic data copy method. It searches for all (parameterless) getter methods in the source object that have a corresponding setter method (with same name but prefixed by "set" instead of "get" and with exactly one parameter) in the destination object.
    For each pair I found I do the following: If the param of the setter type (T2) is assignable from the return type of the getter (T1), I just assign the value. If the types are not compatible, I want to instantiate a new instance of T2, assign it via the setter, and invoke copyData recursively on the object I get from the getter (as source) and the newly created instance (as destination). The assumption is here, that the occurring source and destination objects are incompatible but have matching getter and setter names and at the leaves of the object tree, the types of the getters and setters are compatible so that the recursion ends.
    The core of the problem I am struggling with is the step where I instantiate the new destination object. If T2 is a non-generic type, this is straightforward. However, imagine T1 and T2 are parametrized collections: T1 is List<T3> and T2 is List<T4>. Then I need special handling of the collection. I can easily iterate over the elements of the source List and get the types of the elements, but I can not instantiate only a generic version of the destinatino List. Further I cannot create elements of T4 and add it to the list of T2 and go into recursion, since the information that the inner type of the destination list is T4 is not available at run-time.
    public class Source {
       T1 getA();
       setA(T1 x);
    public class Dest {
       T2 getA();
       setA(T2 x);
    public class BeanDataCopier {
       public static void copyData(Object source, Object destination) {
          for (Method getterMethod : sourceGetterMethods) {
             ... // find matching getter and setter names
             Class sourceParamT = [class of return value of the getter];
             Class destParamT = [class of single param of the setter];
             // special handling for collections -  I could use some help here
             // if types are not compatible
             Object destParam = destination.getClass().newInstance();
             Object sourceParam = source.[invoke getter method];
             copyData(sourceParam, destParam);
    // usage of the method
    Souce s = new Source(); // this is an example, I do not know the type of s at copying time
    Dest d = new Dest(); // the same is true for d
    // initialize s in a complicated way (actually JAX-B does this)
    // copy values of s to d
    BeanDataCopier.copyData(s, d);
    // now d should have copied values from s Can you provide me with any alternative approaches to implement this "duck typing" behaviour on copying properties?
    Best regards,
    Patrik
    PS: You might have guessed my overall use case: I am sending an object tree over a web service. On the server side, the web service operation has a deeply nested object structure as the return type. On the client side, these resulting object tree has instances not of the original classes, but of client classes generated by axis. The original and generated classes are of different types but have the identically named getter and setter methods (which again have incompatible parameter types that however have consistent names). On the client side, I want to simply create an object of the original class and have the values of the client object (including the whole object tree) copied into it.
    Edited by: Patrik_Spiess on Sep 3, 2008 5:09 AM

    As I understand your use case this is already supported by Axis with beanMapping [http://ws.apache.org/axis/java/user-guide.html#EncodingYourBeansTheBeanSerializer]
    - Roy

  • Generics via reflection and newInstance()

    I'm looking for a way, or a correct syntax, for 'genericizing' the
    class instantiation via Class#newInstance() method using reflection.
    The code shown below is an half-baked solution in that compiler emits
    unchecked cast warning against the cast on the 'obj' variable at the
    last part of the code.
    I think I have tried everyting conceivable for Class variable declarations
    and other part of the code but they were all futile. I lost one night
    sleep for that.
    If there are Java Generics gurus on the forum, please help!
    TIA.
    import java.util.*;
    import java.lang.reflect.*;
    public class GetMethod{
      public static void main(String[] args) {
        Object obj = null;
        Class<Hashtable> clazz = Hashtable.class;
        Class<Class> claxx = Class.class;
        try {
          Method method = claxx.getMethod("newInstance");
          obj = method.invoke(clazz);
        catch (Exception e) {
          e.printStackTrace();
        Hashtable<String,String> ht = (Hashtable<String,String>)obj;
        ht.put("foo", "bar");
        System.out.println(ht.get("foo"));
    }

    If you are preparing teaching material, then I would strongly suggest that you do not mix generics with reflection until both are very well understood.
    Using reflection to invoke reflection API methods (or any method known at compile time) as you did in your example, suggests that you do not understand enough yet.
    Because generics are a compile time mechanism and reflection is run time, many of the naive assumptions you might make just wont hold. Reflection is a mechanism for subverting the compiler, don't expect reflection and the compiler to have a harmonious relationship.
    Please remember when writing training material, that the code you use will be assumed by your students to be the best way to solve the problem it purports to solve. You need to bear this in mind when choosing code samples, not only must the sample illustrate the feature being taught, but it must be an appropriate application of that feature. If you do not choose appropriate problems to solve with your illustrative code, you will unwittingly train a generation of incompetents, whose code will be even stupider than yours.
    Bruce

  • Line items  AND GENERIC EXTRACTION

    what does line items exactly mean in DATASOURCES
    AND WHAT ARE DELTA TYPE EXTRACTIONS IN GENERIC
    TIME STAMPING
    CALENDAR DAY
    NUMERICAL POINTER
    COULD ANY PLEASE EXPLAIN THE DIFFERNCE  AND IN WHAT SCENARIOS WE USE IT ...
    LOOKING FOR YOUR REPLY

    Hi Guru,
    Check below doc & thread for Line Item Dimension:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a7f2f294-0501-0010-11bb-80e0d67c3e4a
    Line Item Dimenstion
    If a field (date, progressive document number, timestamp) exists in the extract structure of a DataSource that contains values which increase monotonously over time, you can define delta capability for this DataSource. If such a delta-relevant field exists in the extract structure, such as a timestamp, the system determines the data volume transferred in the delta method by comparing the maximum value transferred with the last load with the amount of data that has since entered the system. Only the data that has newly arrived is transferred.
    To get the delta, generic delta management translates the update mode into a selection criterion. The selection of the request is enhanced with an interval for the delta-relevant field. The lower limit of the interval is known from the previous extraction. The upper limit is taken from the current value, such as the timestamp or the time of extraction. You can use security intervals to ensure that all data is taken into consideration in the extractions (The purpose of a security interval is to make the system take into consideration records that appear during the extraction process but which remain unextracted -since they have yet to be saved- during the next extraction; you have the option of adding a security interval to the upper limit/lower limit of the interval).
    After the data request was transferred to the extractor, and the data was extracted, the extractor then informs generic delta management that the pointer can be set to the upper limit of the previously returned interval.
    To have a clear idea:
    1. If delta field is Date (Record Create Date or change date), then use Upper Limit of 1 day.
    This will load Delta in BW as of yesterday. Leave Lower limit blank.
    2. If delta field is Time Stamp, then use Upper Limit of equal to 1800 Seconds (30 minutes).
    This will load Delta in BW as of 30 minutes old. Leave Lower limit blank.
    3. If delta field is a Numeric Pointer i.e. generated record # like in GLPCA table, then use
    Lower Limit. Use count 10-100. Leave upper limit blank. If value 10 is used then last 10
    records will be loaded again. If a record is created when load was running, those records
    may get lost. To prevent this situation, lower limit can be used to backup the starting
    sequence number. This may result in some records being processed more than once.
    Refer this link from help.sap.com
    http://help.sap.com/saphelp_erp2005/helpdata/en/3f/548c9ec754ee4d90188a4f108e0121/frameset.htm
    Difference between timestamp used in copa and generic data extraction?
    COPA timestamps vs Generic timestamps
    Check this doc for more info:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/84bf4d68-0601-0010-13b5-b062adbb3e33
    Hope these helps u...
    Regards,
    KK.

  • Customer and Generic extraction difference ?

    Hi ya,
    Could any body tell me the difference between the customer and Generic extractions.what are the extraction steps?
    Regards.
    H

    Hi,
    In Generic extraction we have to fetch the data from table/view/funtion module.T.code RSO2.
    Replicate the data source in bw and send into data target through ods(recommandable).
    In customized extraction sap provided LIS,LO-COCKPIT,CO-PA,FI-SL etc,in these sap provides extract stuructures.From the extract structures we have to fetch the data and replicate the data into bw and push into the data targets.
    with regards,
    HARI GUPTA

  • LIS and Generic Extraction

    Hi All,
             Could someone please send me some information regarding LIS extraction and Generic extraction.
    Thanks in advance,
    Sekhar

    Hi Sekhar,
    Please do check the link for step by step for generic xtraction
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/84bf4d68-0601-0010-13b5-b062adbb3e33
    check the following
    http://help.sap.com/bp_biv235/BI_EN/html/bw.htm
    business content
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/g-i/how%20to%20co-pa%20extraction%203.0x
    https://websmp203.sap-ag.de/co
    http://help.sap.com/saphelp_nw04/helpdata/en/37/5fb13cd0500255e10000000a114084/frameset.htm
    (navigate with expand left nodes)
    also co-pa
    http://help.sap.com/saphelp_nw04/helpdata/en/53/c1143c26b8bc00e10000000a114084/frameset.htm
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/fb07ab90-0201-0010-c489-d527d39cc0c6
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1910ab90-0201-0010-eea3-c4ac84080806
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ff61152b-0301-0010-849f-839fec3771f3
    LO Extraction
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f83be790-0201-0010-4fb0-98bd7c01e328
    Check these links:
    /people/sap.user72/blog/2004/12/16/logistic-cockpit-delta-mechanism--episode-one-v3-update-the-145serializer146
    /people/sap.user72/blog/2004/12/23/logistic-cockpit-delta-mechanism--episode-two-v3-update-when-some-problems-can-occur
    /people/sap.user72/blog/2005/01/19/logistic-cockpit-delta-mechanism--episode-three-the-new-update-methods
    /people/sap.user72/blog/2005/02/14/logistic-cockpit--when-you-need-more--first-option-enhance-it
    /people/sap.user72/blog/2005/04/19/logistic-cockpit-a-new-deal-overshadowed-by-the-old-fashioned-lis
    Re: LO-Cockpit  V1 and V2 update
    Also Refer this link:
    http://www.sap-img.com/business/lo-cockpit-step-by-step.htm
    FI-CO 'Data Extraction -Line Item Level-FI-CO
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a7f2f294-0501-0010-11bb-80e0d67c3e4a
    FI-GL
    http://help.sap.com/saphelp_nw04/helpdata/en/c9/fe943b2bcbd11ee10000000a114084/frameset.htm
    http://help.sap.com/saphelp_470/helpdata/en/e1/8e51341a06084de10000009b38f83b/frameset.htm
    http://www.sapgenie.com/sapfunc/fi.htm
    FI-SL
    http://help.sap.com/saphelp_nw2004s/helpdata/en/28/5ccfbb45b01140a3b59298c267604f/frameset.htm
    http://help.sap.com/saphelp_erp2005/helpdata/en/41/65be27836d300ae10000000a114b54/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/ee/cd143c5db89b00e10000000a114084/frameset.htm
    How to do basic LO extraction for SAP-R3-BW
    1. Go to transaction code RSA3 and see if any data is available related to your DataSource. If data is there in RSA3 then go to transaction code LBWG (Delete Setup data) and delete the data by entering the application name.
    2. Go to transaction SBIW --> Settings for Application Specific Datasource --> Logistics --> Managing extract structures --> Initialization --> Filling the Setup table --> Application specific setup of statistical data --> perform setup (relevant application)
    3. In OLI*** (for example OLI7BW for Statistical setup for old documents : Orders) give the name of the run and execute. Now all the available records from R/3 will be loaded to setup tables.
    4. Go to transaction RSA3 and check the data.
    5. Go to transaction LBWE and make sure the update mode for the corresponding DataSource is serialized V3 update.
    6. Go to BW system and create infopackage and under the update tab select the initialize delta process. And schedule the package. Now all the data available in the setup tables are now loaded into the data target.
    7.Now for the delta records go to LBWE in R/3 and change the update mode for the corresponding DataSource to Direct/Queue delta. By doing this record will bypass SM13 and directly go to RSA7. Go to transaction code RSA7 there you can see green light # Once the new records are added immediately you can see the record in RSA7.
    8.Go to BW system and create a new infopackage for delta loads. Double click on new infopackage. Under update tab you can see the delta update radio button.
    9.Now you can go to your data target and see the delta record.
    find your scenario and find what data sources do you need on R3 side and ensure they are active as well:
    http://help.sap.com/saphelp_nw04/helpdata/en/37/5fb13cd0500255e10000000a114084/frameset.htm
    find your scenario -> data sources -> go to R3 -> sbiw and activate required data source
    replicate data sources in BW:
    RSA1 -> source systems -> right click on your source system -> replicate
    then activate your BC:
    service.sap.com/bi -> BI Business Content -> General Information -> SAP BW Business Content - Activation
    and execute infopackage (it should be delivered with BC)
    Useful links:
    http://help.sap.com/saphelp_nw04/helpdata/en/e3/e60138fede083de10000009b38f8cf/frameset.htm
    service.sap.com/bi -> BI InfoIndex
    sdn.sap.com -> Business Information Warehouse -> How-To guides (under Quick Links)
    Hope This Helps.
    ****Assign Points If Helpful****
    Regards,
    Ravikanth

  • Reflection and RTTI

    I need to create references to new objects of leaf classes from the root class in a class hierarchy. I am not sure how to do this. I have considered reflection and RTTI, but with no success.
    I have a hierarchy of classes with several levels. Each class has methods that overrides the methods it inherited. Each of the classes at the bottom of the hierarchy, has a different code for the methods inherited. The root class does not know the existence of the classes at the bottom of hierarchy. The root node receives a "token" from an external source. Based on this "token" (it is a String) it needs to generate a reference to the Object of the class for the "token". Then the root class can apply one of its methods on this reference. This application of method needs to give different results for different references.
    I tried the following approaches. I applied Class.forName(token) to get the Class of the "token". Then I used newInstance() on this Class. An Object refers now the instance. I needed to type cast this object to apply my method to get the desired result. Since I do not know the type of the object, and the class of the object is not loaded at the compile time, I decided to use reflection. I applied getConstructors(), getClass(). Still the problem of type casting to the type of the required class remains unaddressed. Can anyone help? Thanks!

    public abstract class Animal {
        public abstract void vocalize();
        public static Animal create(String name)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException {
            return (Animal) Class.forName(name).newInstance();
        public static void main(String[] args) throws Exception {
            create("Dog").vocalize();
            create("Cat").vocalize();
    class Dog extends Animal {
        public void vocalize() {
            System.out.println("woof");
    class Cat extends Animal {
        public void vocalize() {
            System.out.println("meow");

  • Java reflection and singletons

    Using java reflection and singletons .. anyone seen this being used?

    I've solved it
    I had a singleton but then it turned out i had to use reflection instead, i tried to used reflection on 3 methods but the session value within was null upon the second method call. Relfection was re-creating the Object.
    Sorry for wasting your time.

  • Data Cache and Generic Cache

    Hello,
    According to this document,
    http://download.oracle.com/docs/cd/B16240_01/doc/apirefs.102/e12639/chapter1.htm#CIAEFHFB
    I see there are two cache system in Oracle BI Server, "Data Cache" and "Generic Cache".
    What is the difference between these two kinds of cache ?
    Thanks.

    Hi user611881,
    I'll try to explain the two cache types here, but if someone can better phrase it than myself, by all means, step up.
    Data Cache:
    The OBIEE BI Server will cache the result set of SQL that is executed. These cached results are records and if OBIEE sees another report requesting the same record set that it already has in cache, it will go straight to the cache version instead of re-issuing the SQL
    Generic Cache:
    The generic cache is the presentation server cache. This has to do with the caching of particular request. If the BI Server detects a cached version of a request, it will get the request directly from the cache and not even go down to check for the cached record set.
    This is how they function. Assume you have report A with record set 1 and there's no data in either cache.
    You run Report A
    1) Presentation Service checks if the Request is in the generic cache.
    2) This check fails.
    3) Presentation service issues logical SQL query to BI Server
    4) BI Server checks if there is any record set matching the logical query in the cache
    5) This check fails.
    6) BI Server issues the physical SQL
    7) BI Server caches the result set
    8) Presentation service gets result set and formats the data
    9) Presentation service caches presentation results
    10) Report A is displayed
    That is my understanding of the Data and Generic Caches.
    Good luck and if you found this post useful, please award points!
    Best regards,
    -Joe

  • Forms 9i and Generic Conectivity..

    I've started doing my own business. I design and develop applications for small(mobil) businesses. An application runs on desktop. I have tried to use Forms 6i with a Sybase SQL Anywhere database and it works perfect.
    My question is: How I can by an Oracle Forms and Generic Connectivity Solutions without anything else?
    Does Oracle think about desktop and mobil user market?
    To buy Developer Suite is very expensive. Or should I move toward Sybase Powerbuilder?
    Thanks.
    Vas

    Vas,
    actually Forms6i is the last client/server release of Forms, which means that starting Forms9i it only supports Web deployment. Forms6i client/server support (error correction) ends in end 2004 which means that after 2004 Forms is available on teh Web only. I can imagine that this is not the desktop strategy that you had in mind, but actually it is what the statement of direction on OTN says.
    For mobile support, I think that you mean stand alone (laptop) based applications. Real mobile applications wont work using Forms because there is no certified technology for this right now.
    regards
    Fran

  • Missing reflection and captions

    I have been sending out my iWeb addresses to my friends and one, who has both a PC and a Mac, reported that when the site was opened and the slide show is loaded and played on the PC, the reflection and captions were present, but when Safari was used on the Mac Mini, no reflection and captions were visible. Does anyone have a suggestion as to why this happened, and what could be done about it? I want my captions to be able to be viewed when watching the slide show.
    Thank you.

    I have discovered that, at least in one case, when a Mac user opens my sites with FireFox, the captions don't show and Windows users can use IE or FireFox and the captions show, but the reflections do not.

  • Client would like the monetary fields to reflect . and not , in the fields.

    Client would like the monetary fields to reflect . and not , in the fields. There are commas and he wants decimals.
    can any one help me out, this is a tkt  can any one suggest me how do we take it further.

    Hi Jai Ram,
    Ask the user to go to SU3 tcode. Then go to defaults tab. There is a field called Decimal Notation. There are three formats as below
    1.234.456,789
    1,234,456.789
    1 234 456,789
    Select accordingly. Then quit SAP and relogin. The changes will be applied.
    Kind Regards
    sandeep

  • Reflections and shadows

    Can the Forum members give me any links or tips on creating light reflections and shadows? I'm restoring a photo of my old street rod and I have painted it using layers and all the body lines show through but I need to add light reflections to make it look glossy and real. Barbara Brundage are you there? I looked in your book but maybe not in the right place. I use white, the blur tool and layers to create reflections and black and same for shadows. Thanks to all that reply

    Web Site Maestro. It optimizes and uploads. It also has a "smart handling" feature that that allows you to process the changed files only.
    Very fast and efficient.
    http://www.tonbrand.nl/
    Also see...
    http://www.iwebformusicians.com/SearchEngines/Optimize.html

  • Difference between fully-specified data types. and generic types

    Hi,
    Can anyone tell me the difference between fully-specified data types and generic types.
    Thanks in advance.
    Regards,
    P.S.

    HI
    Generic table types
    INDEX TABLE
    For creating a generic table type with index access.
    ANY TABLE
    For creating a fully-generic table type.
    Data types defined using generic types can currently only be used for field symbols and for interface parameters in procedures . The generic type INDEX TABLEincludes standard tables and sorted tables. These are the two table types for which index access is allowed. You cannot pass hashed tables to field symbols or interface parameters defined in this way. The generic type ANY TABLE can represent any table. You can pass tables of all three types to field symbols and interface parameters defined in this way. However, these field symbols and parameters will then only allow operations that are possible for all tables, that is, index operations are not allowed.
    Fully-Specified Table Types
    STANDARD TABLE or TABLE
    For creating standard tables.
    SORTED TABLE
    For creating sorted tables.
    HASHED TABLE
    For creating hashed tables.
    Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
    Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
    see this link
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb366d358411d1829f0000e829fbfe/content.htm
    <b>Reward if usefull</b>

Maybe you are looking for

  • GR/IR account functionality

    Dear Guru's, Any one please calarify, how gr/ir account functions iam not clear about this one, what i understand is 1)GR/IR account is a gl account with open item managed one. 2) when goods received it was posted by crediting to this account and deb

  • Error occurred during initialization of VM & java/lang/NoClassDefFoundError

    ascertain:tcglive:~/BUILD/bin> ./listJobs Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ascertain:tcglive:~/BUILD/bin> ./startJobServer -fg Error occurred during initialization of VM java/lang/NoClassDefF

  • CC installation stops searching file server at 2%

    Hi I try to update the newest version, but the installation stops at 2% with the message "searching server'. PC W78 is connected to internet. Did relaunch, but no change. This since 2 days now Thanks for your help

  • OEPE invalidates other additional Eclipse plugins

    Hi everybody, we use Eclipse 3.7.2 (JEE Edition) using the "-configuration" parameter. I´ve installed several additional plugins, for example the CDT tool. CDT is working, as I am (for example) able to open "C/C++ perspective". Then I installed OEPE

  • NetBoot not working since 10.6 upgrade

    Hi all. I recently upgraded from Server 10.5.8 to 10.6.3 (DVD) with software update to 10.6.4. Everything with the migration went without incident. DNS, DHCP, Open Directory, NFS and AFP are all working perfectly (including network accounts, etc.). I