Reflection with something like class MyClass T extends Date {...}

assume you have:
//first class
class Message {
//second class
class ConcreteMessage extends Message{
//third class
public class WrapperBase<J extends Message> {
    private J message = null;
    public J getMessage() {
        return message;
    public void setMessage(J message) {
        this.message = message;
    public WrapperBase(J message){
        this.message = message;       
//fourth class
class WrapperExtended extends WrapperBase<ConcreteMessage>{
    public WrapperExtended(ConcreteMessage message) {
        super(message);
}Reflecting on the WrapperExtended I obtain the getter(for example)
WrapperExtended ext = new WrapperExtended(message);
Method extMethod =ext.getClass().getMethod("getMessage", new Class[0]);If I check the class of the extMetihd return type I obtain a Message, not a ConcreteMessage as I expected. How can I retrieve the info that the method returns a ConcreteMessage?
Development environment knows that the return type is a ConcreteMessage,so I guess there must me some reflection mechanism to retrieve it.

If I check the class of the extMetihd return type I obtain a Message, not a ConcreteMessage as I expected. How can I retrieve the info that the method returns a ConcreteMessage?
Development environment knows that the return type is a ConcreteMessage,so I guess there must me some reflection mechanism to retrieve it.
Yes, for classs derived from a concrete generic instantiation (such as WrapperBase<String>) you can find the concrete return type via reflection. Here's the code that does the trick:
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
class Message {
//second class
class ConcreteMessage extends Message{
//third class
class WrapperBase<J extends Message> {
    private J message = null;
    public J getMessage() {
        return message;
    public void setMessage(J message) {
        this.message = message;
    public WrapperBase(J message){
        this.message = message;       
    public static Class<?> findConcreteReturnType(Class<? extends WrapperBase<?>> cl, String methodName, Class<?>...params) throws SecurityException, NoSuchMethodException {
         Method extMethod = cl.getMethod(methodName, params);
         if(!(extMethod.getGenericReturnType() instanceof TypeVariable))
              return extMethod.getReturnType();
         TypeVariable<?> genericReturnType = (TypeVariable<?>)extMethod.getGenericReturnType();
         String variableName = genericReturnType.getName();
         ParameterizedType genericSuperclass = (ParameterizedType) cl.getGenericSuperclass();
         TypeVariable<Class<WrapperBase>>[] typeParameters = WrapperBase.class.getTypeParameters();
         for(int i = 0; i < typeParameters.length; ++i) {
              if(typeParameters.getName().equals(variableName)) {
               Type type = genericSuperclass.getActualTypeArguments()[i];
               if(!(type instanceof Class))
                    throw new IllegalArgumentException("class "+cl.getName()+" does not resolve type parameter "+ variableName);
               return (Class<?>)type;
     throw new InternalError();
//fourth class
public class WrapperExtended extends WrapperBase<ConcreteMessage>{
     public WrapperExtended(ConcreteMessage message) {
super(message);
public static void main(String[] args) throws SecurityException, NoSuchMethodException {
          System.out.println(WrapperBase.findConcreteReturnType(WrapperExtended.class, "getMessage"));

Similar Messages

  • Reflection with proxy home class

    Hello !
    I'm trying to perform some common code to invoke method on home computed with the reflection API (code without try/catch):
    Object homeref = initial.lookup(compName);
    Class xClass = homeref.getClass();
    InvocationHandler invctHandler = Proxy.getInvocationHandler(homeref);
    Method findByPrimaryKey = xClass.getMethod("findByPrimaryKey", new Class[] {scopedAidClass});
    object = invctHandler.invoke(homeref, findByPrimaryKey, new Object[] {scopedAid});
    at runtime I get an invalid invocation exception.
    I have define correctly the ejb-external-ref to be able to use the bean on which I'm invoking the home.
    I know somewhere the code has to be downloaded into the proxy. So I tried to narrow the homeref with the PRO - though in local:
    Object homestub = (Object)PortableRemoteObject.narrow(homeref, thisHomeClass);
    without any effect, still getting the same proxy and getting the same exception at runtime.
    Thank you for any help.
    seb.

    Hi ,
    Instead of using below line of code
    object = invctHandler.invoke(homeref, findByPrimaryKey, new Object[] {scopedAid});
    use this :
    object = findByPrimaryKey .invoke(homeref, new Object[] {scopedAid});
    I hope it shows some solution to your problem.
    Regards,
    Santhosh

  • Backing up an eMac with something like Carbonite ?

    I just had a crash with my old eMac and had to do a clean install. I had previously looked for automatic backup like Carbonite (which doesn't cover any Mac machine), but never found one online which impressed me.  Question: Can anyone recommend a service similar to Carbonite for Macintosh users? 

    Dropbox...
    https://www.dropbox.com/pricing
    http://wiki.getdropbox.com
    But I prefer a local backup using Firewire drives &...
    Get carbon copy cloner to make an exact copy of your old HD to the New one...
    http://www.bombich.com/software/ccc.html
    Or SuperDuper...
    http://www.shirt-pocket.com/SuperDuper/
    Or the most expensive one & my favorite, Tri-Backup...
    http://www.tri-edre.com/english/products/tribackup.html

  • When I try to download the newest version of Firefox, it pops up with a box saying do you want to save this binary file with something like daimaijin.mirror in the address. Is this a safe thing to do or is it spyware or something?

    If I cancel it and try it again, the same binary file box pops up with a different address.

    Mozilla has download mirror websites around the globe and uses them to "balance" the downloads of Firefox so users don't need to "wait in line" for their download.
    Here's a listing of those mirrors. <br />
    http://www.mozilla.org/community/mirrors.html

  • Encoding small videos with something like ffmpeg and viewable from safari

    Hello,
    Using ffmpeg, I am able to convert working video for the iPhone when they are transfered by iTunes.
    ffmpeg -r 25 -f mp4 -vcodec mpeg4 -ar 48000 -ab 128000 -b 700000 -s 480x320 -i any.video video.mp4
    However, I wish to be able to download small videos that I daily put on a webserver, and this is not working when downloading video.mp4:: "This movie could not be played."
    Does anyone know the accepted format by Safari+Quicktime ?

    Hey d3yv. I'm not sure if it's enough info for you but here's what I found on p. 138 of the manual...
    The following video file formats are supported by iPhone:
    - H.264 (Baseline Profile Level 3.0)
    - MPEG-4 (Simple Profile)
    http://manuals.info.apple.com/enUS/iPhone_UserGuide.pdf

  • Class parametrized type extends and implements, possible?

    Hi all,
    Maybe I'm not understanding it well, but every time I try to use generics for something useful I get to a point in which I need to define something like this:
    public interface MyInterface<T> {
    public T get();
    public void set(T var);
    public class MyClass<T extends Component & MyInterface<T2> > {
    T myObject;
    .... somewhere in the code:
    T2 value;
    value = myObject.get();
    To me, this would be very useful, but MyClass does not compile. I hope what I try to do is clear (I want T to be a sub class of Component that also implements a parametrized interface). I don't know what I'm doing wrong nor if this is even possible. Believe me when I say I have done a lot of research (and people thought C++ templates where complicated...).
    My main problem is having a parametrized type that contains a parametrized type and trying to have both types' parameters available for use in the class.
    Any ideas?

    This compiles in beta2:
    public class MyClass<T2, T extends Component & MyInterface<T2> > {
       T myObject = null;
      void x() {
          myObject.bar();
          T2 a = myObject.get();
    interface MyInterface<T> {
          T get();
          void set(T var);
    class Component {
        public void bar() {}
    }but removing the public modifier from Component.bar() will give the error: cannot find symbol.

  • Help with Defining a Class

    I wrote a program that reads files and parses the contents. This information is stored in a vector and then this vector is stored in another vector.
    This is a simplified version of the code.
    Vector Row = new Vector();
    Vector Field = new Vector();
    Field.addElement("Date");
    Field.addElement("Title");
    Field.addElement("Version");
    Row.addElement(Field);How can I do this by defining a class? I don't have to use a Vector for the Field information. ArrayList will do the job. I want to be able to store the information that I parse from the fill using something like:
    myDocument Fields = new myDocument;
    Fields.addDate("Date");
    Fields.addTitle("Title");
    etc...
    Row.addElement(Fields);All the information parsed out is a String. When I used the .addDate, it should convert the String into a Date.
    .addVersion would convert the String to an integer.
    This class stuff sure is confusing.
    I think I need to do something like:
    class myDocument extends ArrayList {
         Date myDate;
         String myTitle;
         int myVersion;
    public myDocument() {
    /code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    That does help. I wasn't sure if I was on the right track with how to define the class. I added some comments to the code below. Do my comments make sense? Do I understand the terminology and flow of this class?
    So my class would look like this:
    class myDocument extends HashMap{
         Date myDate;  //these are called class variables???
         String myTitle;
         int myVersion;
    public addDate(String dateString) {
          SimpleDateFormat dtFormat = new SimpleDateFormat("MM/dd/yyyy");
          myDate = dtFormat.parse(dateString);
          this.put("Data", myDate);
    public addTitle(String titleString) {
          myTitle = titleString;  //Don't think I need this. Can just this.put("Title", titleString);???
          this.put("Title", myTitle);
    public addVersion(String versionString) {
          int myVersion = Integer.parseInt(versionString);
          this.put("Version", myVersion);
    public myDocument() { //constructor???  Do nothing in here because I am creating a simple HashMap???
    }The program would call the class like this:???
    Vector Row = new Vector();
    myDocument Field = new myDocument(); //This creates a Field object that really is a HashMap with some new methods???
    Field.addDate(parsedString);// Calls the .addDate method in the myDocument class;  In the method, this.put would be the same as Field.put if Field was a HashMap not a myDocument???
    Field.addVersion(parsedString);
    Row.addElement(Field); // Store the new class in a Vector called Row

  • What Perspective Grid settings for something like this?

    This has been confounding my for more time than I care to admit. How would I set up a Perspective Grid for something like this? I don't know where to begin. I'm used to drawing simlple buildings from an eye-level view, but obviously with something like this, the viewer is looking way up .

    Hello Cheryl,
    This is technically a 3P perspective; you mentioned the viewer is looking way up - such a scene is called worm's eye view.
    I tried setting up a grid over the image. The point where the two red lines meet is the third Vanishing Point. The two other VPs are to be located by extending the two yellow and the two green lines till they intersect in the direction shown by the two arrows. However this will be at an infinite distance and this way the view can be thought of as 1P perspective as Jet & Michael have opined. Remember that camera lenses can create skewed and distorted perspective. Illustrator's grid cannot match that. Moreover Illustrator's grid is also limited by the application's canvas size i.e., the entire grid has to fit in the canvas. When drawing on a sheet of paper you can actually visualize one or more VP out of your drawing sheet.
    Anyway the closest approximation to this kind of perspective can be achieved in Illustrator by placing the image on the top of the canvas such that the 3rd VP lies almost on the top edge of the canvas. The eye-level in case of worm's eye view is zero. So the horizon line coincides with the ground line and both lie virtually on the bottom edge of the canvas. The left & right grid will then let you to draw the walls of the building as above.

  • MyClass T extends MyClass T problem

    Hi, I have the following two abstract classes in the same package:
    public abstract class State <T> {
      private T owner;
      void setOwner(T owner) {
        this.owner = owner;
    public abstract class MyClass <T extends MyClass<T>> {
      private State<T> state;
      public void setState(State<T> state) {
        this.state = state;
        this.state.setOwner(this);
    }The idea is that if I create a new class, say MyClassSub, that extends MyClass, then it should supply itself as the type parameter for MyClass, eg:
    public class MyClassSub extends MyClass<MyClassSub> {
    }The point of this is that when such a class is created, it can only set subclasses of State<MyClassSub> as its "state" variable, and the "owner" variable in the state is automatically updated within the setState method. (Notice how the setOwner method is hidden from public, visible only inside the package).
    The problem is that this doesn't compile. I get the error:
    setOwner(T) in State<T> cannot be applied to (MyClass<T>)
       this.state.setOwner(this);
       ^Any ideas?

    Thanks for your reply.
    My understanding is that you are trying to assign a
    supertype to a subtype, and so the compiler is right
    to complain.That is correct, however, since MyClass is abstract I will only ever assign a subtype.
    More specifically the offending line is
    "this.state.setOwner(this);"
    where:
    - "this.state" is of type T, and the setOwner()
    method, according to your definition of class State,
    thus expects a type T
    - "this" is of type MyClass<T>
    Your class type parameter says precisely "T extends
    MyClass<T>", in other words T is a subtype of
    MyClass<T>. You are thus not allowed to assign a
    MyClass<T> instance where a T instance (or a subtype
    of T) is expected.Yep, "this" is MyClass<T> at the moment, however it will be of type MyClassSub extends MyClass<MyClassSub> etc, when it actually executes. The reason I am doing this is because I have a few subclasses of MyClass.
    So, I would rewrite MyClass definition as follows:
    public abstract class MyClass <T extends MyClass<T>>
    private State<MyClass<T>> state;
    public void setState(State<MyClass<T>> state) {
    this.state = state;
    this.state.setOwner(this);
    See that I use the proper instantiation of generic
    State class, by using State<MyClass<T>>This works ok, however, it might as well not use generics since the State class would only ever allow the class MyClass and not a subtype as I wanted in the first place. i.e, I would like to have State class specific to each subtype: e.g, State<MyClassSub1>, State<MyClassSub2>, etc. where MyClassSub1 and MyClassSub2 are subclasses of MyClass<MyClassSub1> and MyClass<MyClassSub2> respectively.

  • I have an installation CD Adobe Acrobat 9 Pro with teh Serial No/key. Now I bought a tablet that has now CD drive. So I tried to download the Acrobat 9 Pro from the Adobe hoempage, but failed. I can only find the link to something like an extended version

    I have an installation CD Adobe Acrobat 9 Pro with teh Serial No/key. Now I bought a tablet that has now CD drive. So I tried to download the Acrobat 9 Pro from the Adobe hoempage, but failed. I can only find the link to something like an extended version. So how do I have to proceed , where can I find the proper link. My system has W 8.1 32 Bit.

    Try the download below...
    You can download the trial version of the software thru the page linked below and then use your current serial number to activate it.
    Be sure to follow the steps outlined in the Note: Very Important Instructions section on the download pages at this site and have cookies enabled in your browser or else the download will not work properly.
    CS5: http://prodesigntools.com/all-adobe-cs5-direct-download-links.html

  • Something like a list with components... how to?

    First of all forgive me for the topic title, i couldnt find any better...
    My problem is :
    Id like to create something like a clickable list with graphics to keep trace of actives file transfers.
    In my program i used a JList with a string for each transfer but i would like to improve it, maybe adding a progress bar and some buttons to each list row.
    Is this possible?
    Thanks for the help,
    JNoobNite

    Is this possible?Nothing is impossible
    Id like to create something like a clickable list with graphics to keep trace of actives file transfers.It can be done
    In my program i used a JList So continue using a JList (well I believe it will work). Have you read up on ListCellRenderers? Here is one that allows you to have a checkbox in the JList, which can be checked and unchecked: http://www.geocities.com/icewalker2g/downloads/IconedCellRenderer.java
    i would like to improve it, maybe adding a progress bar and some buttons to each list rowUsing a JList in this case might be too much work. Instead, you could use JPanels (probably a custom class which has all the components, ie buttons, progressbars, icons, and then use some kind of model architecture to manage them ie, retrieve, remove, add, etc. This should allow you to easily interact with the components.
    That's my 3 and a half cents
    ICE

  • Malicious or not? Message popped up: Mozilla security found (something like too much, forget exact word) activity on your computer so it will do a fast scan of system file. With OK button.

    I was looking at youtube.com, which always tells me my browser is not supported and recommends I download Firefox, but that is what I was using, so I went to Firefox to check for updates. (I think I also had freecycle.org open.) Then this message popped up in a new page: Mozilla security found (something like "too much", forget exact word) activity on your computer so it will do a fast scan of system file. There was an OK button. The page address was: http://update17.stegner.ce.ms/index.php?Q7Lhl9ShbRxGJXpkM1VLSi4ZE8H4pTedoVPySgeppM3VpC+thEspcFG7qxHgn1pdsC2h5ygPGWI3t5hXqMzL9EQaZZ3J1e3CKXgCb0Qp. I did not click OK but copied the link and closed the window which closed the internet. I have never seen this before and would like to know if it is really Mozilla or possibly something malicious. Thank you.

    Good catch. That almost certainly is an invitation to download malware.
    There are a lot of infected web sites pushing "fake antivirus" software. If you have any doubts about whether your system might have become infected, you can supplement your regular security software with these two highly regarded scanners:
    Malwarebytes Anti-malware : http://www.malwarebytes.org/mbam.php
    SUPERAntiSpyware : http://www.superantispyware.com/

  • Hi Team, I wuold like to know if you have any app to make Firefox OS working with cisco Call Manager 10.5. Something like Cisco Jabber for Android or iOS.

    I'm interesting on buying a Firefox Smart Phone, but
    I would like to know if are any app to install on Firefox OS smart phone in order to work with cisco call manager 10.5.
    Something like Cisco Jabber for Android o iOS.
    Thanks,

    Hi Itech,
    If Cisco Jabber has a webapp, or mobile version of their website available, you should technically be able to access it through Firefox OS.
    You may also search Firefox Marketplace for an alternative solution:
    * [https://marketplace.firefox.com/]
    - Ralph

  • I am doing a lot of presenting with the ipad and want an app that would bullseye or show where I am to my audience. Anyone know of something like this?

    I am doing a lot of presenting with the ipad and want an app that would bullseye or show where I am to my audience. Anyone know of something like this?

    It sounds like either your hard drive or the SATA cable that connects it to the motherboard are failing. This could be heat related in your case, which is why you see it after it runs awhile. You can take it to the Genius Bar for a free evaluation. If you decide to test it yourself, I usually suggest moving the hard drive to an external enclosure. If it works there for awhile, the cable is probably the issue.
    http://www.amazon.com/Sabrent-2-5-Inch-Aluminum-Enclosure-EC-TB4P/dp/B005EIGUD4/ ref=sr_1_3?ie=UTF8&qid=1397647657&sr=8-3&keywords=2.5+enclosure
    http://www.ifixit.com/Device/MacBook_Pro_13%22_Unibody_Mid_2009

  • I ran a virus/trojan fix and this is what it said it could not repair something in the main library core or something like that.  What do I do?  The problem seems to be with safari?

    I ran a virus/trojan fix and this is what it said it could not repair something in the main library core or something like that.  What do I do?  The problem seems to be with safari?

    I ran the utility disk and this is what it said.
    Warning permission differ Applications/Safari drwxr-xrx they are -rwxr-xr system/livrary Cores has been modified and will not be repaired.
    Permission apllication differ on System/livrary/Pr or could be -rw-r--r-- they are rwxr-xr-x Application/iTune be droxr-xr-x they are rwxr-xr-x
    Then I hit fix permissions and it said this
    Warning SUID file Systm/Library/Core has been modified will not be repaired
    I also downloaded Bitdefender Virus Scanner and it found nothing.

Maybe you are looking for

  • Which ID i should provide

    It's sounds a bit stupid. I'm using a Airport Extreme in a Static IP network. The network will distributing IP based on pre-registered MAC address. From the back of the Device, there's two ID number 'Airport ID' And 'Ethernet ID' which one i should g

  • Joining iTunes songs not from CD import

    I have been collecting an mp3, AAC, m4a, etc... music library in iTunes for many years now. My old CDs are in storage because they're all burned onto my iPod, iPhone, MacBook, and Time Capsule for backup. When I purchase music these days it's almost

  • Combine PDF Pages automator step strips annotations

    Oh, I was so excited when I noticed the Combine PDF Pages command in Automator. Then I was less excited when I discovered that if any of the pages has annotations created in Acrobat Pro, those annotations are removed from the newly combined PDF. Sinc

  • How to commit in master detail block

    Hi I have a master and a detail block . In detail block if i try to insert a record and commit it is working fine . But when i try to insert multiple records then I am unable to commit . Error given is frm 40508 :Unable to insert record . Plz help me

  • Editing contact card info

    Exchange 2010 sp3, outlook 2013 i know how to edit the contact card details (like the phone numbers, position, etc.) but how does one edit the graphical part? below, the person's name and position are showing in the upper left corner but the position