Problem referencing to methods with generic type parameters

Assuming I have an interface like to following:
public interface Test <T> {
void test ( T arg0 );
void test ( T arg0, Object arg1 );
I would like to reference to both "test"-methods using "{@link #test(T)}" and "{@link #test(T,Object)}".But this generates an error telling me "test(T)" and "test(T,Object)" cannot be found.
Changing T to Object in the documentation works and has as interesing effect. The generated link text is "test(Object)" but the generated link is "test(T)".
Am I somehow wrong? Or is this a known issue? And is there a workaround other than using "Object" instead of "T"?

Hi,
I bumped into the same problem when documenting a generic.
After quite a while of search your posting led me to the solution.
My code goes something like this:
public class SomeIterator<E> implements Iterator<E> {
  public SomeIterator(E[] structToIterate) {
}When I tried to use @see or @link with the constructor Javadoc never found it.
After I changed the documentation code to
@see #SomeIterator(Object[])it worked.
Since both taglets offer the use of a label, one can easily use these to produce comments that look correct:
@see #SomeIterator(Object[]) SomeIterator(E[])CU
Froestel

Similar Messages

  • Generic method invocations with explicit type parameters

    If I interpret the JSR14 public draft spec (June 23, 2003) section 5.6 correctly the following method invocations with explicit type parameters should compile: package generics;
    public class G121 {
      void f() {
        this.<String>f2();
        <String>f2(); // compilation error
        <String>f3(); // compilation error
      <T> void f2() {
      static <T> void f3() {
    }but the class does not compile: jc -J-showversion generics\G121.javajava version "1.5.0-beta"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
    Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
    generics\G121.java:6: illegal start of expression
        <String>f2(); // compilation error
                ^
    generics\G121.java:8: illegal start of expression
        <String>f3(); // compilation error
                ^
    2 errors
    >A bug or do I miss something?

    I get this error:
    LineCount.java:104: cannot find symbol
    symbol : method <java.io.File>sort(java.util.List<java.io.File>)
    location: class java.util.Collections
    Collections.<File>sort( list );
    ^
    1 errorYou don't need the explicit type argument there, but anyway...
    If you look at the docs for Collections.sort(List<T> list) you'll see it is declared as:
    static <T extends Comparable<? super T>> void Collections.sort(List<T> list) Unfortunately, although File implements Comparable, it doesn't actually implement Comparable<File> or even Comparable<Object>, so I guess it can't satisfy the bound.
    You can get it to compile by removing the explicit type argument and casting to the raw type List, but that's not very nice.
    This seems like an oversight to me - File already has both int compareTo(Object o) and int compareTo(File pathname) so I don't see why it can't implement Comparable<File>. This isn't the only such case in the API though, so maybe I'm missing something.
    Mark

  • Import from database an internal table with generic Type : Web Dynpro ABAP

    Hi everyone,
    i have a requirement in which i'm asked to transfer data flow between two frameworks, from WD Component to another. The problem is that i have to transfer internal tables with generic types. i used the import/ export from database approache but in that way i get an error message saying "Object references and data references not yet supported".
    Here is my code to extract a generic internal table from memory.
        DATA l_table_f4 TYPE TABLE OF REF TO data.
      FIELD-SYMBOLS: <l_table_f4> TYPE STANDARD TABLE.
      DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
      DATA: ls_indx TYPE indx.
      lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
      lo_componentcontroller->fire_vh_search_action_evt( ).
      ASSIGN l_table_f4 TO <l_table_f4>.
    *-- Import table for Help F4
      IMPORT l_table_f4 TO <l_table_f4> FROM DATABASE indx(v1) TO ls_indx ID 'table_help_f4_ID'.
    The error message is desplayed when last instruction is executed " IMPORT l_table_f4...".
    I saw another post facing the same problem but never solved "Generic Type for import Database".
    Please can anyone help ?
    Thanks & Kind regards.

    hi KIan,
    go:
    general type
    TYPE : BEGIN OF ty_itab,
               field1 TYPE ztab-field1,
               field2 TYPE ztab-field2,
    *your own fields here:
               field TYPE i,
               field(30) TYPE c,
               END OF ty_itab.
    work area
    DATA : gw_itab TYPE ty_itab.
    internal table
    DATA : gt_itab TYPE TABLE OF ty_itab.
    hope this helps
    ec

  • A question about a method with generic bounded type parameter

    Hello everybody,
    Sorry, if I ask a question which seems basic, but
    I'm new to generic types. My problem is about a method
    with a bounded type parameter. Consider the following
    situation:
    abstract class A{     }
    class B extends A{     }
    abstract class C
         public abstract <T extends A>  T  someMethod();
    public class Test extends C
         public <T extends A>  T  someMethod()
              return new B();
    }What I want to do inside the method someMethod in the class Test, is to
    return an instance of the class B.
    Normally, I'm supposed to be able to do that, because an instance of
    B is also an instance of A (because B extends A).
    However I cannot compile this program, and here is the error message:
    Test.java:16: incompatible types
    found   : B
    required: T
                    return new B();
                           ^
    1 errorany idea?
    many thanks,

    Hello again,
    First of all, thank you very much for all the answers. After I posted the comment, I worked on the program
    and I understood that in fact, as spoon_ says the only returned value can be null.
    I'm agree that I asked you a very strange (and a bit stupid) question. Actually, during recent months,
    I have been working with cryptography API Core in Java. I understood that there are classes and
    interfaces for defining keys and key factories specification, such as KeySpec (interface) and
    KeyFactorySpi (abstract class). I wanted to have some experience with these classes in order to
    understand them better. So I created a class implementing the interface KeySpec, following by a
    corresponding Key subclass (with some XOR algorithm that I defined myself) and everything was
    compiled (JDK 1.6) and worked perfectly. Except that, when I wanted to implement a factory spi
    for my classes, I saw for the first time this strange method header:
    protected abstract <T extends KeySpec> T engineGetKeySpec
    (Key key, Class<T> keySpec) throws InvalidKeySpecExceptionThat's why yesterday, I gave you a similar example with the classes A, B, ...
    in order to not to open a complicated security discussion but just to explain the ambiguous
    part for me, that is, the use of T generic parameter.
    The abstract class KeyFactorySpi was defined by Sun Microsystem, in order to give to security
    providers, the possibility to implement cryptography services and algorithms according to a given
    RFC (or whatever technical document). The methods in this class are invoked inside the
    KeyFactory class (If you have installed the JDK sources provided by Sun, You can
    verify this, by looking the source code of the KeyFactory class.) So here the T parameter is a
    key specification, that is, a class that implements the interface KeySpec and this class is often
    defined by the provider and not Sun.
    stefan.schulz wrote:
    >
    If you define the method to return some bound T that extends A, you cannot
    return a B, because T would be declared externally at invocation time.
    The definition of T as is does not make sense at all.>
    He is absolutely right about that, but the problem is, as I said, here we are
    talking about the implementation and not the invocation. The implementation is done
    by the provider whereas the invocation is done by Sun in the class KeyFactory.
    So there are completely separated.
    Therefore I wonder, how a provider can finally impelment this method??
    Besides, dannyyates wrote
    >
    Find whoever wrote the signature and shoot them. Then rewrite their code.
    Actually, before you shoot them, ask them what they were trying to achieve that
    is different from my first suggestion!
    >
    As I said, I didn't choose this method header and I'm completely agree
    with your suggestion, the following method header will do the job very well
    protected abstract KeySpec engineGetKeySpec (Key key, KeySpec key_spec)
    throws InvalidKeySpecException and personally I don't see any interest in using a generic bounded parameter T
    in this method header definition.
    Once agin, thanks a lot for the answers.

  • How to get instance of Class with its type parameters

    Hi,
    Have any of you folks been dealing with generics long enough to show me how this should be written? Or point me to the answer (I have searched as well as I could).
    I boiled down my situation to the included sample code, which is long only because of the inserted comments. And while boiling I accidentally came across a surprise solution (a bug?), but would obviously prefer a smoother solution.
    My Questions (referred to in the code comments):
    #1. Is there a way to get my parameterized type (classarg) without resorting to using the bogus (proto) object?
    #2. Can anyone understand why the "C" and "D" attempts are different? (All I did was use an intermediate variable????) Is this a bug?
    Thanks so much for any input.
    /Mel
    class GenericWeird
       /* a generic class -- just an example */
       static class CompoundObject<T1,T2>
          CompoundObject(T1 primaryObject, T2 secondaryObject)
       /* another generic class -- its main point is that its constr requires its type class */
       static class TypedThing<ValueType>
          TypedThing(Class<ValueType> valuetypeclass)
       // here I just try to create a couple of TypedThings
       public static void main(String[] args)
          // take it for granted that I need to instantiate these two objects:
          TypedThing<String>                        stringTypedThing = null;
          TypedThing<CompoundObject<String,String>> stringstringTypedThing = null;
          // To instantiate stringTypedThing is easy...
          stringTypedThing = new TypedThing<String>(String.class);
          // ...but to instantiate stringstringTypedThing is more difficult to call the constructor
          Class<CompoundObject<String,String>> classarg = null;
          // classarg has got to be declared to this type
          //    otherwise there will rightfully be compiler error about the constructor call below
          // This method body illustrates my questions
          classarg = exploringHowToGetTheArg();
          // the constructor call
          stringstringTypedThing = new TypedThing<CompoundObject<String,String>>(classarg);
       } // end main method
       // try compiling this method with only one of A,B,C,D sections uncommented at a time
       private static Class<CompoundObject<String,String>> exploringHowToGetTheArg()
          Class<CompoundObject<String,String>> classarg = null;
          /* Exhibit A: */
      ////     classarg = CompoundObject.class;
             results in compiler error "incompatible types"
             found   : java.lang.Class<GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = CompoundObject.class;
                                            ^
             I understand this.  But how to get the type information?
          /* It's obnoxious, but it looks like I will have to construct a temporary
              prototype instance of type
                 CompoundObject<String,String>
              in order to get an instance of
                 Class<CompoundObject<String,String>>
              (see my Question #1) */
          CompoundObject<String,String> proto = new CompoundObject<String,String>("foo", "fum");
          /* Exhibit B: */
      ////     classarg = proto.getClass();
             results in compiler error: "incompatible types"
             found   : java.lang.Class<capture of ? extends GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = proto.getClass();
                                            ^
          /* Exhibit C: */
      ////     classarg = proto.getClass().asSubclass(proto.getClass());
             results in compiler error: "incompatible types"
             found   : java.lang.Class<capture of ? extends capture of ? extends GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = proto.getClass().asSubclass(proto.getClass());
                                                         ^
          /* Exhibit D: (notice the similarity to C!): */
      ////     Class tmp1 = proto.getClass();
      ////     classarg = tmp1.asSubclass(tmp1);
          /* It compiles (see my Question #2) */
          return classarg;
       } // end method exploringHowToGetTheArg()
    } // end class GenericWeird

    Thanks so much, Bruce. (Oh my goodness, how would I have ever come up with that on my own?)
    So in summary
    This doesn't compile:
          classarg = (Class<CompoundObject<String,String>>)CompoundObject.class;but these do compile:
          classarg = (Class<CompoundObject<String,String>>)(Class)CompoundObject.class;or
          Class coclass = (Class)CompoundObject.class;
          classarg = (Class<CompoundObject<String,String>>)coclass;And this doesn't compile:
           classarg = proto.getClass().asSubclass(proto.getClass());but this does:
           Class tmp1 = proto.getClass();
           classarg = tmp1.asSubclass(tmp1);

  • How to create an array with Generic type?

    Hi,
    I need to create a typed array T[] from an object array Object[]. This is due to legacy code integration with older collections.
    The method signature is simple:public static <T> T[] toTypedArray(Object[] objects)I tried using multiple implementations and go over them in the debugger. None of them create a typed collection as far as I can tell. The type is always Object[].
    A simple implementation is just to cast the array and return, however this is not so safe.
    What is interesting is that if I create ArrayList<String>, the debugger shows the type of the array in the list as String[].
    If I create ArrayList<T>, the class contains Object[] and not T[].
    I also triedT[] array = (T[]) Array.newInstance(T[].class.getComponentType(), objects.length);And a few other combinations. All work at runtime, create multiple compilation warnings, and none actually creates T[] array at runtime.
    Maybe I am missing something, but Array.newInstace(...) is supposed to create a typed array, and I cannot see any clean way to pass Class<T> into it.T[].class.getComponentType()Returns something based on object and not on T, and T.class is not possible.
    So is there anything really wrong here, or should I simply cast the array and live with the warnings?
    Any help appreciated!

    Ok. May be you could keep information about generic type in the your class:
    public class Util {
        public static <T> T[] toTypedArray(Class<T> cls, Object[] objects){
            int size = objects.length;
            T[] t = (T[]) java.lang.reflect.Array.newInstance(cls, size);
            System.arraycopy(objects, 0, t, 0, size);
            return t;
    public class Sample<T> {
        Class<T> cls;
        T[] array;
        public Sample(Class<T> cls) {
            this.cls = cls;
        public void setArray(Object[] objects){
            array = Util.toTypedArray(cls, objects);
        public T[] getArray(){
            return array;
        public static void main(String[] args) {
            Object[] objects = new Object[] { new LinkedList(), new ArrayList()};
            Sample<List> myClass = new  Sample<List>(List.class);
            myClass.setArray(objects);
            for(List elem: myClass.getArray()){
                System.out.println(elem.getClass().getName());
    }

  • [ANN] Java IDE with generic type support

    Hello all!
    We are proud to announce that we have just released version 5.0 of our Java IDE CodeGuide.
    CodeGuide 5.0 offers full support for generic types as defined in JSR 14. Features are:
    - Fast incremental on-the-fly compilation
    - On-the-fly error checking of the whole project
    - Code completion
    - Usage search
    - Refactoring (like Renaming, Class moving, etc.)
    - and more...
    A 30-day trial can be downloaded from our web page at
    http://www.omnicore.com
    Any feedback regarding JSR 14 support is much appreciated.
    Best regards,
    Dennis Strein
    Omnicore Software

    I wrote a class MultiMap<K, V> extends Map<K, Set<V>>
        // Various constructors, methods, fields.
        public Set<V> get(K key)
            // Implementation
    } It compiles fine with the Sun reference compiler, but a friend tells me that CodeGuide 5.0 build 504 complains "There already is another method with the same erasure." It could be that CodeGuide is correct and Sun wrong, because I can see that there might be issues with overriding the get(Object) method with a get(K), but I thought I'd mention it.

  • Obtaining Generics type parameters using reflection

    I have been trying to obtain the type parameters of a method using reflection. This is what I have done:
    getGenericTypeParameters(aMethod.getTypeParameters());
    private static String getGenericTypeParameters(TypeVariable genericParameters[])
           String returnName = new String();
                   if(genericParameters.length > 0)
                           returnName += "< ";
                           for(int i=0; i<genericParameters.length; i++)
                                   if(i > 0) returnName += ", ";
                                   returnName += genericParameters.getName();
    returnName += " >";
    return returnName;
    } This doesn't take care of the cases when the method is of the form  public static <T, V extends T> boolean isIn(T x, V[] y)
    and the type parameters I get using the method I've written is <T, V>
    Is there any workaround or a better way of doing it?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Have you consulted Angelika Langer's [Java Generics FAQs|http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html]?

  • Static Methods with all Final Parameters

    Gurus,
    I know the synchronization and static method question has been hashed out ad infinitum here. However, I was thinking of a slight twist. (Did a search but could not find something related to this. If this has already been posted, my apologies).
    Suppose you have a static method in which all of the parameters in the method signature are declared final. Let's assume also that you are not performing an operation with a high latency (say, database or network operations).
    Would it be "safe" to leave the static method unsynchronized in a multi-threaded environment? Would the final keyword(s) ensure that, throughout method execution, there is no longer a race condition?
    Would there be a difference between a primitive:
    static final public void doSomething(final int param) {}
    And an object that has mutator methods:
    static final public void doSomething(final List param) {}
    Basically, not having a formal CS background, I'm not sure how static methods are actually invoked on a low-level. It probably varies across JVM's, and maybe this question doesn't make much sense. However, I thought I would throw this out to see if anyone had implemented something similar.
    I might be giving "final" too much credit., but what would actually happen in a multi-threaded environment?
    Thanks much!
    - Saish
    "My karma ran over your dogma." - Anon

    I know the synchronization and static method question
    has been hashed out ad infinitum here. What question's that then?
    Suppose you have a static method in which all of the
    parameters in the method signature are declared final.
    Let's assume also that you are not performing an
    operation with a high latency (say, database or
    network operations).
    Would it be "safe" to leave the static method
    unsynchronized in a multi-threaded environment?Whether or not the parameters are final makes no difference - method parameters are local to the method and so are only visible to the current thread anyway. So making them final will have no effect on anything goning on in any other thread.
    Whether or not you are performing operations has no effect on whether or not you can call a method thread-safe. It might mean there is less contention and it might make race conditions less likely, but it won't eliminate them.
    So the answer is: If your would be thread safe with non-final parameters, then it will still be thread-safe when the parameters are all final. If it is not thread-safe with non-final parameters, then it will still not be thread safe with final parameters.
    Would the final keyword(s) ensure that, throughout
    t method execution, there is no longer a race
    condition?No. Absoloutely not.

  • Problem in structure start with charecter type

    i am doing a upgrade of an abap program which is written in 4.6 to  ecc 6.0 i am facing a unicode error problem
    in the old program there is  a sap standrad structure called arc_buffer  so in this program they have used the structure  as
    below code
        PERFORM read_file USING handle_tab_wa-offset record_len
                          CHANGING arc_buffer(record_len)
                                   error_handling
                                   p_message.
    so when it is used as arc_buffer(record_len)   system is giving unicode error like
    '' the structure arc_bufffer(record_len) does not start with a charecter type field' 
    as the structure is sap standard  i think i cannot change the stadard structure so what should be done to get out of this error.

    the structure arc_buffer has following fields
    RCSZK
    RNAME
    CHECKSUM
    FLAGS
    SEGMENT
    so in the routine
    PERFORM read_file USING handle_tab_wa-offset record_len
    CHANGING arc_buffer(record_len)  "here just use it like arc_buffer-<field_name>(record_len)
    error_handling
    p_message.
    or before calling the perform statement
    data:lv_string type string.
    call method cl_abap_container_utilities=>fill_container_c
    exporting
    im_value = arc_buffer
    importing
    ex_container = lv_string
    exceptions
    illegal_parameter_type = 1
    others = 2.
    PERFORM read_file USING handle_tab_wa-offset record_len
    CHANGING lv_string(record_len)  "here just use it like arc_buffer-<field_name>(record_len)
    error_handling
    p_message.

  • Problem in FEBA / FB05 with document type

    Hi:
    I have a requirement. My users need the possibiliyu to choose the document type when they use FEBA TX. When FEBA is used, it calls FB05 TX, but you cannot choose the document class. We have defined a posting rule that uses in only a document type in this case, but when we use FEBA we cannot change document type. We need the possibility to choose several document types. I tried with OB28 Validation of Accounting Documents, but doesn`t work.
    Please, do
    you have any idea, user exit or solution for this problem? Release 4.6.C
    Thanks in advance.
    Best regards

    the structure arc_buffer has following fields
    RCSZK
    RNAME
    CHECKSUM
    FLAGS
    SEGMENT
    so in the routine
    PERFORM read_file USING handle_tab_wa-offset record_len
    CHANGING arc_buffer(record_len)  "here just use it like arc_buffer-<field_name>(record_len)
    error_handling
    p_message.
    or before calling the perform statement
    data:lv_string type string.
    call method cl_abap_container_utilities=>fill_container_c
    exporting
    im_value = arc_buffer
    importing
    ex_container = lv_string
    exceptions
    illegal_parameter_type = 1
    others = 2.
    PERFORM read_file USING handle_tab_wa-offset record_len
    CHANGING lv_string(record_len)  "here just use it like arc_buffer-<field_name>(record_len)
    error_handling
    p_message.

  • Problem LSMW + IDOC method for message type : MATMAS

    hi friends,
      I am using LSMW + IDOC method Message : MATMAS , idoc type : MATMAS03 .Setting every thing are fine. Finally Material is not created with error "message have been issued number : <idoc number>".
    data : material, industry type, material type, description, Basic unit of mesure.
    Please  help me.
    Balaji.T.

    Hi,
    I have nothing found regarding your issue. But maybe a look at SAP note 638058 will give you a hint.
    Regards,
    Klaus

  • Implementing Empty Versions of Interface Methods with Return Types

    Subject probably is probably a bit long but I was stumped for a brief way to summarize my question. Let's say I have the interface below:
    public interface DAO {
        ...snip...
        public Object get(int id);
        public Object[] get(String clause);
        ...snip...
    }From this I want to make two concrete classes, say ClassOne and ClassTwo. Given the type of data each one is fetching, ClassOne only needs (and should only) implement get(int id) and ClassTwo only needs (and should only) implement get(String clause). This is because the first class will always deal with only one record from table_a and the second class will always deal with one or more records from table_b. So my question is what is the correct way to provide empty implementations for the unnecessary methods?
    I've thought of using an adapter to implement empty methods but a) I'm not sure that makes sense and b) I still end up have to return something. Another option was maybe having multiple interfaces, one returning a single object and the other returning an array. Neither of those options felt right and looked a bit goofy when I prototyped them out. It seems to me that I wouldn't want the classes using the concrete DAO classes to be able to call the wrong method, but I don't know how to hide the unused method. Right now I just return an empty Object or Object[] for the unused method but that seems goofy too, and makes the class using ClassOne or ClassTwo know the innards of the implementations.
    Anyway, any tips appreciated.
    Thanks,
    Pablo

    It sounds as if the methods weren't meant to be together, and so I'm wondering if you aren't better off with two distinct interfaces, one for each method. Otherwise one solution would be to implement a method that throws an exception if it is not meant to be called.
    edit: D'oh! Just when you least expect them, Ninjas! They're everywhere!
    Edited by: Encephalopathic on Apr 30, 2009 1:41 PM

  • Overriding abstract methods with generic argument

    Hi,
    This post is similar to the one posted just before it :
    [http://forum.java.sun.com/thread.jspa?threadID=5281500|http://forum.java.sun.com/thread.jspa?threadID=5281500]
    I am trying to override an abstract method which has a generic argument and a problem occurs. I would like to find out whether what I am trying to do is not legal. The point of interest here is that the overriding class reduces the scope of the abstract class.
    The Abstract class AbstractAdapter defines accessors for a collection containing objects derived from AbstractPort. (<? extends AbstractPort>)
    The overriding class Adapter overrides these accessors but reduces the scope of the collection objects from <? extends AbstractPort> to <Port>. Port
    Here is my abstract class:
    public abstract class AbstractAdapter {
         public abstract Collection<? extends AbstractPort> getPorts();
         public abstract void setPorts(Collection<? extends AbstractPort> ports);
    }And here is the class that overrides it:
    public class Adapter extends AbstractAdapter {
         public Collection<Port> getPorts() {
              return null;
         public void setPorts(Collection<Port> ports) {
    }The Port class is shown here:
    public class Port extends AbstractPort {
    }Edited by: BenDave on Apr 2, 2008 4:39 AM

    It's not really the same.
    I don't have a compiler to hand, so this is off the top of my head. I expect you want something like this:
    public abstract class AbstractAdapter<T extends AbstractPort> {
         public abstract Collection<T> getPorts();
         public abstract void setPorts(Collection<T> ports);
    public class Adapter extends AbstractAdapter<Port> {
         public Collection<Port> getPorts() {
              return null;
         public void setPorts(Collection<Port> ports) {
    }

  • Problem in calling method with object in another class

    Hi All,
    Please tell me the solution, I have problem in calling a method I am posting the code also
    First Program:-
    import java.io.*;
    public class One
    public One()
    System.out.println("One:Object created");
    public void display()
    System.out.println("One:executing the display method");
    static
    System.out.println("One:executing the static block");
    Second Program:-
    import java.io.*;
    public class Two
    public Two()
    System.out.println("Two:Object created");
    public static void main(String arg[])throws Exception
    System.out.println("Two:executing the main method");
    System.out.println("Two:loading the class and creating the object::One");
    Object o=Class.forName("One").newInstance();
    System.out.println(o);
    o.display(); //displaying error here in compile time.
    static
    System.out.println("Two:executing the static block");
    waiting for your answer,
    thanks in advance,bye.

    Hi All,
    Please tell me the solution, I have problem in
    calling a method I am posting the code also
    First Program:-
    import java.io.*;
    public class One
    public One()
    System.out.println("One:Object created");
    public void display()
    System.out.println("One:executing the display
    method");
    static
    System.out.println("One:executing the static
    block");
    Second Program:-
    import java.io.*;
    public class Two
    public Two()
    System.out.println("Two:Object created");
    public static void main(String arg[])throws
    Exception
    System.out.println("Two:executing the main
    method");
    System.out.println("Two:loading the class and
    creating the object::One");
    Object o=Class.forName("One").newInstance();
    System.out.println(o);
    o.display(); //displaying error here in compile
    time.
    static
    System.out.println("Two:executing the static
    block");
    waiting for your answer,
    hanks in advance,bye.the line
    o.display()
    could be written as
    ((One)o).display();

Maybe you are looking for