Invoking super constructor of a parameterized class

Hi all,
I am getting a rather surprising warning messge
"Type safety: The constructor Super(Class) belongs to the raw type Super. References to the generic type Super<T> should be parameterized."
Of course, if the super constructor accepts Class instead of Class<T>, then everything is OK.
I've tried all sorts of things to get rid of this, all to no effect. What to do?
public class Super<T> {
     public Super(Class<T> c) {
public class Sub extends Super {
     public Sub(Class<Object> c) {
          // warns on the following line:
          super(c); 
}Thanks for any help!
Marc

Or, if Sub is to be generic:
public class Sub<T> extends Super<T> {
  public Sub(Class<T> c) {
}

Similar Messages

  • Invoked super class constructor means create an object of it?

    Hei,
    i have create one class that extends another class. when i am creating an object of sub class it invoked the constructor of the super class. thats okay.
    but my question is :
    constructor is invoked when class is intitiated means when we create an
    object of sub class it automatically create an object of super class. so means every time it create super class object.

    Hi,
       An object has the fields of its own class plus all fields of its parent class, grandparent class, all the way up to the root class Object. It's necessary to initialize all fields, therefore all constructors must be called! The Java compiler automatically inserts the necessary constructor calls in the process of constructor chaining, or you can do it explicitly.
       The Java compiler inserts a call to the parent constructor (super) if you don't have a constructor call as the first statement of you constructor.
    Normally, you won't need to call the constructor for your parent class because it's automatically generated, but there are two cases where this is necessary.
       1. You want to call a parent constructor which has parameters (the automatically generated super constructor call has no parameters).
       2. There is no parameterless parent constructor because only constructors with parameters are defined in the parent class.
       I hope your query is resolved. If not please let me know.
    Thanks & Regards,
    Charan.

  • Invoke super class constructor of super class' parent class

    I would like to invoke a constructor of a super class that is the parent of the direct super class. For instance:
    class C extends class B, and class B extends class A.
    From class C, is it possible to invoke class A's constructor without first invoking class B constructor?
    Something like super.A() ??
    Thanks.
    Joe

    try this,
    abstract class GrandParent
          private Object pObj = null;
          protected Via via = new Via();
          protected class Via
             public Object doMethod1( Object obj )
                pObj = obj;
                return "GrandParent m1: " + pObj;
             public Object doMethod2( Object obj )
                pObj = obj;
                return "GrandParent m2: " + pObj;
             public Object get()
                return "gp get: " + pObj;
          public abstract Object doMethod1( Object obj );
          public abstract Object doMethod2( Object obj );
          public abstract Object get();
    class Parent extends GrandParent
          private Object pObj = null;
          public Object doMethod1( Object obj )
          pObj = obj;
          return "Parent m1: " + pObj;
          public Object doMethod2( Object obj )
          pObj = obj;
          return "Parent m2: " + pObj;
          public Object get()
          return "p get: " + pObj;
    public class GPMethod extends Parent
          public static void main( String[] args )
          GrandParent gp = new Parent();
          System.out.println( gp.doMethod1( "calling parent" ) );
          System.out.println( gp.doMethod2( "calling parent m2" ) );
          System.out.println( gp.get() );
          System.out.println( "" );
          System.out.println( gp.via.doMethod1( "calling via to GP" ) );
          System.out.println( gp.via.doMethod2( "calling via to GP m2" ) );
          System.out.println( gp.via.get() );
    }

  • How to find out which class invoked the constructor

    i wrote a class named DAOBase and i am creating object of the same in several other classes. So is there any way to know which class has invoked the constructor of DAOBase.
    i want to print out the name of the class that invoked the constructor of DAOBase at the time of constructor invocation...
    Is there any way?
    Please Help...

    Alternatively, use SecurityManager.getClassContext() as inclass CallerAndMain {
         public static void main(java.lang.String[] args) {
              System.out.println("I'm in " + new SecurityManager() { public String getClassName() { return getClassContext()[1].getName(); } }.getClassName() + " class");
              new Try();
    class Try {
         public Try() {
              System.out.println("I'm in " + new SecurityManager() { public String getClassName() { return getClassContext()[1].getName(); } }.getClassName() + " class");
              System.out.println("I was called from " + new SecurityManager() { public String getClassName() { return getClassContext()[2].getName(); } }.getClassName() + " class");
    }

  • Super() constructor must be first. Is it right?

    My previous discussion abot the this issue has been removed. I must reconstruct it to be aware of advantages, disadvantages and bypasses over the restriction.
    Obvously, the restriction prevents us from writing some perfectly valid code:
    class Unsigned7BitOscillatorInputStream extends OscillatorInputStream {
         Unsigned7BitOscillatorInputStream(
              PeriodicSignal signal,
              float amplitude,
              float signalFrequency,
              AudioFormat f,
              long framesLength)
              // call super substituting the audio format
              super(
                   signal,
                   amplitude,
                   signalFrequency,
                   new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
                        f.getSampleRate(),
                        8, f.getChannels(),
                        f.getFrameSize(),
                        f.getFrameRate(),
                        false
                   framesLength);
         }It is the same if one writes
    class Unsigned7BitOscillatorInputStream extends OscillatorInputStream {
         Unsigned7BitOscillatorInputStream(
              PeriodicSignal signal,
              float amplitude,
              float signalFrequency,
              AudioFormat f,
              long framesLength)
              // create audio format for super class, overriding bps
              AudioFormat format = new AudioFormat(
                   AudioFormat.Encoding.PCM_UNSIGNED,
                   f.getSampleRate(),
                   8,
                   f.getChannels(),
                   f.getFrameSize(),
                   f.getFrameRate(),
                   false);
              super(signal, amplitude, signalFrequency, format, framesLength);
         }Fortunately, the new AudioFormat obect can be created inline with super call. Nevertheless, actually, anyway, the instantiation of the local object preceeds the super call. So what was the reason to prevent java programmers from writing strightforward code, make them decieving themselves and looking for ugly bypasses? What if some comuptation must be done and some fields initialized before super can be called? What if I want to log the arguments passed before calling the super constructor? I wonder how java designers know in which order the fields must be initialized/accessed. IMO, it is exactly constructor's competence.

    Java was specifically constructed with limitations in
    mind based on experience with common problem areas.
    Notice that I said "specifically".Does it mean they all the OOP practices are the best? Should I use them as a reference? Which kind of errors does it protect me from? I would like to see a document telling that calling super constructor is evil, really. Peahaps the reasons lie not in best OOP practice but rather some technical/historical sad fact. It would be amusing if you are defending somenes mistake. I'm sure is java did not initially had the real type (float point) for the reason of its support complexity, the java bigots today would prove that the real numbers are evil and the requirement to use this type in your program points to a flaw in your design. The paramount evidence on the best programming practices will, of course, be the JLS bible. Like they prove there must not be a Set.get(key) in the set class/interface. They tell me that there must be none need to request an object of the same class ("class" in math terms) equivalent to that one you have put into the set. They tell me that if I need the method, my design is flawed. However, actually, the lack of the method in java.collections is nothing more than their designer's mistake. The most obvious illustration are relational tables in DB: the keys are parts (fields, members) of records (entities, objects) while tables are nothing more than sets of objects. Using maps in this case is inappropriate and inferes redundancy. But that's another story... Though the superfirst requirement also adds the extra complexity and must be thoroghly justified. Any artifical overcomlication/redundancy must have a solid evidence. IMO, the objected limitation looks like a 5th wheel in a java-telega.
    I have programmed with gotos many years ago. My experiance proves the Dykstra's (one of the structural programming fathers) thesis stating the "gotos are evil". The gotos break the flow of control making it hard to follow. Therefore, I readitly accept it. I have never seen the thesis, but I'm sure I can find and refer it to you if you like. At the same time, I'm sure there is nothing similiar in OOP domain telling the "deferred" supercons are evil. Otherwise, you would be more specific in references. Suppose, someone confines you into a prison, argumenting this is a "specific tool/limitation" to prevent "some" problems. Will you agree? You will insist on some more serious criminations? Be happy - they tell you - you are allowed to argument against the confinement appealing to our community (the community are the people believing the authority blindly)! No, it is accepted in justice that any limitation of freedom must be justified, not the contrary! This is called a presumption of innocence. I suffer, I break my mind when I know that the following invocations are the same but the second does not work for some queer reason:
              B() {
              super(computePrereq());
         B() {
              r = computePrereq(); // why this is worse than above? Where is the justice?
              super(r);
    I think you can find more than a couple of C++
    best practices books and articles that will tell
    you how C++ constructors should be built.Wow, you refer me to C++ as a citadel for OOP best practices! OK. CPP::STL "package" has the get_by_key method in the Set class/template. Will this fact chagne the mind of java bigots? Obviously not, they immediately refuse your arguments just hearing c++. I can, but just please be more specific. I may to carefully explore a ton of books without finding any sign of super second is evil.
    My favorite lang on Wintel platform is Delphi. Many thoughtful people consider it as a Wintel native java. However, there is even no recommendation to use superconstructors first. And the broad experience suggests me that there is nothing harmful in deferring the superconstruction. I do not feel any nasty frustration similar to exploiting gotos. The super destructors must be called last indeed, since they ultimately call the root superclass's (TObject) destructor, which deallocs the mem and the object ceases to exist after the call. But constructors do not alloc any mem for the object fields, they just fill the fields. The order of initialization is absolutely free. The initialization of all the fields may even be made in parallel for performance.
    Delphi also has a interface-resolution mechanism. Two interfaces conflict when they specify two aliasing methods. Will you tell that it is a bad design if happens that two interfaces conflict? The Divide&Concure disign rule tells the contrary, it is bad design when you must care about other blocks developing one. It is java which has design flaw - you must care about names of methods in other interfaces. This is the experiance collected from wast SW/HW methodologies I can share with java community.
    Show me why I cannot construct a human without
    first
    producing an ape?
    False analogy. I doubt that anyone would ever
    construct an inheritence hierarchy like that.I do not belive in God either ;)
    The evolution took itself.
    Or construct a tree without first
    producing a plant? And that would be logically inconsistent. A tree is
    a plant. If plant does not exist then a tree can not
    either.OK. Which plant should I create before proceeding to construct a tree? Do you understand that the Plant and Tree are the classes while an instance of the Tree just belongs to these classes? The calsses are loaded prior to construction. Now, I'm creating a tree. It is not your matter how the tree is created. You just get a tree and if it is a valid tree; that is, your tree implements all methods of the interface the tree class commits to implement, then it is also a plant. The construction technology is not important. The constructor knows it better when to create a steam and leafs.
    Your analogies are a bit absurd. There are other
    more relevent ones though...
    Employee (parent) -> surpervisor (child).
    Based on your argument it is stupid to have a
    supervisor who is an employee. Whereas in the world
    I live in the vast majority of the time supervisors
    are employees. And in the cases where they aren't
    (rare contractual situations) then building a
    hierarchy that reflects that relationship is a design
    flaw which has nothing to do with construction.Where did I argument against this relatioship? Nevertheless, if it bothers you I can tell you my opinion. In the manager-workers pattern, the emploee (also called a manager) is a job, whos duty consists of finding the workers, hand out a job to them and accepting (supervising) the work done. It may also stimulate/motivate the workers, but that is not important. What's more important is that the surpervision is one of manager's duties. Any Manager is a supervisor by definition. Thus, I can explain why Ape and Human are two different classes in the ancestor-descendant relationship, but I cannot explain you manager-supervisor subclassing... I would establish an Employee class implementing its duty interfaces listed. At least, since multiinheritance is not supported in java and you'll have a problem deriving the Emploee from both task initiator and inspector. If you like.
    The plant appears
    altogether with a tree. Talking in a scientigic
    language, being a plant is nothing more than an
    attribute of a tree (which cannot appearahead of the
    object). They appear simultaneously and are
    indistinguishble as a single whole.You said it not me. If you are using attributes and
    nothing else to construct inheritence then your
    design is flawed.Excuse me for not understanding/appretiating your humor. The "Tree" objects are attributed to "Plants" class. Don't you agree of what?
    To put it bluntly, this is you who seem to use inappropriete terminology. In programming, the parent-children relationship is used for tree structures (has-a). Parent may have (or own) a set of children. However, no parent construction precedes the construction of every "child" object. Otherwise, we would get too many parents. While we need descedants. The descedants have attributes of parents but they are not separate objects. Like keyfields in a DB records. All the fields are equal (if we do not toudch the pragmatic level). The ancestor-descendant terminology is adoped in OOP (the talks about inheritance). In java, super/sub-class notation is accustomed. This sharpens my confusion on which "parents" should I create before initializing any new object specific fields.
    Looks like a demagogic sentence. Let's think of a
    human as a brain-increased ape without tail. Do
    again?) or proceeded directly?
    Again you are using a very bad example for
    inheritence.I fail to see why the natural exapmles of inheritance are somehow "bad". OK, not all apes are brain-low, since humen break this rule.
    No, but I can make a soudspeaker without bringingits
    "parent" (presumably, a soundsystem) into "a valid
    state". I can write a java program withoutbringing
    some "abstract" program into a valid state.
    Even worse example. A "sound system" is a
    collection of other objects.
    There is no way that a speaker is ever a child or a
    parent of an amplifier.Thereofore, an abstract soundsystem may not have any concrete descendants? A soundsystem consumes a stream of databits or continous electric signal and produces sound waves. A laudspeaker near to me is full of controls - volume, bass, ets.. What is it if not an incarnation of a sound system?
    OK, here is another example. A floppy-disk is a disk. Should one produce a disk before making it floppy? Or microwave owen is an owen. How do you think should I create an owen prior to making it a microwave? Or electric field, how do I create a field prior to adding the electric parameters? Or how do I construct a hammer if you require me to precede its construction by construction of abstract instrument? How do I manufacturers produce "parent" computers before attaching "personal" properties to it? I'm sure there are millions of ways to construct a PC but none of them requires producing some "parent".
    OK, which chapter of CS tells that "parents" mustbe
    created prior to a "children"? Should Intel start
    manufacturning their Pentium chips by producing8088
    core first? I am beginning to think that you have a substantially
    different view than most people about what
    inheritence means.
    I find it hard to believe that anyone, in any
    situation, would ever attempt to create an
    inheritence tree using 8080 as the parent and a
    pentium as the child. This is a historical
    relationship not a child parent one.The Pentioum extends functionality of 8088 (both HW and SW). Engeneers started more and more features at the core. Finally they got a huge monster. It still starts as 8088. A program can call for extended capabilities if it knows about them. The old programs work on Pentium using its 8088 inherited interface.
    What do you mean telling "parent in valid
    state"? In construction, only ONE object isproduced,
    which complies to its ancestor interface.
    Constructors just aid the process. May be youwanted
    to tell there is no analogy between OOP and the
    nature?A tree is a plant. It is nonsense to suggest that a
    tree can exist before plant exists.As I have told, I have never suggested for such a nonsense. The Plant class exits long before you create an instance of a tree.
    That has nothing to do with the relationship between
    an acorn and an oak however. Nor does the fact that
    an oak produces acorns mean that there is a child
    parent relationship in terms of OO in there.I have never told that the seeds are plants. Moreover, I do not see any relation here with your proir argument that the creation of instance of an oak must be preceeded by the creation of instantance of some abstract plant (belonging to a Plant class) and the tree instance constructor then must decorate the the basic structure of that plant instance.
    Please refer me to a book telling that fields of superclass must be initialized prior to (not after and not concurrently) with the new fields exposed by a subclass.

  • Implicit super constructor is undefined.

    I'm getting this error:
    Implicit super constructor WeightedMeasurement is undefined. Must explicity invoke another constructor.
    WeightedMeasurement is an abstract class in apache.commons.math. So no, it does not have a constructor as such, though it does define 2:
    WeightedMeasurement(double weight, double measuredValue)
    WeightedMeasurement(double weight, double measuredValue, boolean ignored)So I I tried to override like so:
    import org.apache.commons.math.estimation.WeightedMeasurement;
    public class MyWeightedMeasurement extends WeightedMeasurement {
         public MyWeightedMeasurement() {
              String s = new String();
         public MyWeightedMeasurement(double weight, double measuredValue, int x) {
              new MyWeightedMeasurement();
    }but no dice.
    What do I need to do?
    I searched, but didn't find any help.

    I tried the following and it works:
    public abstract class ATestConst
         int computedValue = 0;
         public ATestConst(int val1, int val2)
              computedValue = val1 * val2;
    public class TestingConst extends ATestConst
         int myComputedValue = 0;
         public TestingConst(int v1, int v2, int v3)
              super(v1, v2);
              myComputedValue = super.computedValue / v3;
              System.out.println("My Computed Value: " + myComputedValue);
         public static void main(String[] args)
              int value1 = Integer.parseInt(args[0]);
              int value2 = Integer.parseInt(args[1]);
              int value3 = Integer.parseInt(args[2]);
              new TestingConst(value1, value2, value3);
    }

  • Trying to inherit a super constructor

    Lets suppose I have a parent and child.
    public class Parent{
    public Parent(String string){
    //do some stuff here
    public class Child{
    and finally some other class using the child
    pubilc class myChildTester{
    pubilc static void main(String[] args){
    Child child = new Child("heres a string");
    //do some stuff with it
    Now i completely understand that this itself wont work, since the child does not have that constructor. What I want to do is to somehow force the child to know enough to use the super constructor. However, I dont want to have to do something fancy like change the java compiler obviously. Also, no code is to be added to the child.
    The reason I ask this is because in reality I have a similar situation. In that case though the parent has three different constructors the child needs. However the child only ever uses the "super" constructor, without adding any other functionality. Also, instead of just one child, I have maybe 100 different ones. I dont want to have to copy and paste the constructor that just calls "super" every single time. This is just pure laziness, but I see absolutely no reason why java wouldnt know enough to do this, since it does it already for the default constructor (and even that only works conditionally).
    Also, doing something like making another method in the parent (i.e. like a getInstance(String string) method) that the child could use. I must have the constructor, because I'm using Spring to do some stuff on these classes.
    I highly doubt there actually IS a way to do anything around this. But any suggestions would be appreciated

    and no constructor with a super call.Well, the language is very clear: Constructors are not methods and not inherited.
    You have the brittle superclass problem.
    One way to handle your situation is to replace the constructors in the parent class with factory methods with the same parameter list as the constructor. In addtion the factory method is supplied information about which child should be created, like
    class Parent {
       public static Parent create(ChildType type, T1 p1, T2 p2)  { // factory method
          Parent p = null;
          switch (type) { // create proper child
              Cld1: p = new Child1(); break;
              Cld2: p = new Child2(); break;
              // do the constructors work
          p.setP1(p1);
          p.setP2(p2);
          return p;  
    class Child1 extends Parent {
    class Child2 extends Parent {
    Parent p1 = Parent.create(Cld1, 0, 1);
    Parent p2 = Parent.create(Cld2, 1, 0);

  • Generic static methods in a parameterized class

    Is there anything wrong with using generic static methods inside of a parameterized class? If not, is there anything special about defining them or calling them? I have a parameterized class for which I'd like to provide a factory method, but I'm running into a problem demonstrated below:
    class MyClass<T> {
         private T thing;
         public
         MyClass(T thing) {
              this.thing = thing;
         public static <U> MyClass<U>
         factoryMakeMyClass(U thing)     {
              return new MyClass<U>(thing);
    class External {
         public static <U> MyClass<U>
         factoryMakeMyClass(U thing)     {
              return new MyClass<U>(thing);
    class Test {
         public static void
         test()
              // No problem with this line:
              MyClass<String> foo = External.factoryMakeMyClass("hi");
              // This line gives me an error:
              // Type mismatch: cannot convert from MyClass<Object> to MyClass<String>
              MyClass<String> bar = MyClass.factoryMakeMyClass("hi");
    }Does this code look ok to you? Is it just a problem with my ide (Eclipse 3.1M2)? Any ideas to make it work better?

    I've been working on essentially the same problem, also with eclipse 3.1M2. A small variation on using the external class is to use a parameterized static inner class. I'm new enough to generics to not make definitive statements but it seems to me that the compiler is not making the correct type inference.
    I think the correct (or at least a more explicit) way of invoking your method would be:
    MyClass<String> bar = MyClass.<String>factoryMakeMyClass("hi");
    See http://www.langer.camelot.de/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ401
    See http://www.langer.camelot.de/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ402
    Unfortunately, this does not solve the problem in my code. The compiler reports the following error: The method myMethod of raw type MyClass is no more generic; it cannot be parameterized with arguments <T>.
    Note that in my code MyClass is most definitely parameterized so the error message is puzzling.
    I would like to hear from more people on whether the sample code should definitely work so I would appreciate further comments on whether this an eclipse problem or my (our) misunderstanding of generics.     

  • Trouble invoking Axis service with multiple parameters

    Hallo Java experts,
    I have a problem with Axis 1.2RC2 (and Tomcat 5.0.19, JDK 1.5, Win XP) that might be quite simple, but I'm not so experienced and running out of ideas.
    Everything works fine as long as I use a single Parameter. But I can't invoke service methods with more parameters, independent of the parameters' (simple) types! Different exceptions are thrown, depending on the way I invoke the service. It's either ...
    - a java.lang.IllegalArgumentException (case 1)
    "Tried to invoke method public java.lang.String test.server.TestSoapBindingImpl.printLongs(long,long) with arguments java.lang.Long,null. The arguments do not match the signature."
    - or an org.xml.sax.SAXException (case 2)
    "SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize."
    Here's an example of a simple web service, that takes two longs and should return a string. In case 1 the service is invoked using a service locator in case 2 with a 'Call' object and explicitly set parameter types.
    Thanks in advance for your help!
    Dave
    service[b]
    public class TestSoapBindingImpl implements test.server.Test{
      public String printLongs(long long_1, long long_2){
        return "long_1 = " +long_1 +", long_2 = " +long_2;
    [b]case 1
    client
    public class TestClient {
      public static void main (String[] args) throws Exception {     
        TestService service = new TestServiceLocator();
        Test testProxy = service.gettest();     
        long longVal = 1L; 
        response = testProxy.printLongs(longVal, longVal);
        System.out.println(response);
    SOAP messsage
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
          <in6 xmlns="urn:TestNS">1</in6>
          <in7 xmlns="urn:TestNS">1</in7>
       </soapenv:Body>
    </soapenv:Envelope>
    Axis' log file
    Part of the log, where only the first argument of 'printLongs' is properly converted before the exception is thrown.
    17886  org.apache.axis.utils.JavaUtils
            - Trying to convert java.lang.Long to long
    17886  org.apache.axis.i18n.ProjectResourceBundle
            - org.apache.axis.i18n.resource::handleGetObject(value00)
    17886  org.apache.axis.providers.java.RPCProvider
            -   value:  1
    17886  org.apache.axis.i18n.ProjectResourceBundle
            - org.apache.axis.i18n.resource::handleGetObject(dispatchIAE00)
    17986  org.apache.axis.providers.java.RPCProvider
            - Tried to invoke method public java.lang.String test.server.TestSoapBindingImpl.printLongs(long,long) with arguments java.lang.Long,null.  The arguments do not match the signature.
    java.lang.IllegalArgumentException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:384)
          at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:281)
         at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:319)
         at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
         at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
         at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
         at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:450)
         at org.apache.axis.server.AxisServer.invoke(AxisServer.java:285)
         at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:653)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
         at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:301)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    case 2
    client
    public class TestClient2
      public static void main(String [] args) {
        try {
           String endpoint =
             "http://localhost:1234/axis1.2rc2/services/test";
           Service  service = new Service();
           Call     call    = (Call) service.createCall();
           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperationName(new QName("urn:TestNS", "printLongs") );
           call.addParameter("in6",
                             org.apache.axis.Constants.XSD_LONG,
                             javax.xml.rpc.ParameterMode.IN);
           call.addParameter("in7",
                             org.apache.axis.Constants.XSD_LONG,
                             javax.xml.rpc.ParameterMode.IN);
           call.setReturnType(org.apache.axis.Constants.XSD_STRING);
           String response = (String) call.invoke( new Object[] { 1L, 1L } );
           System.out.println(response);
        } catch (Exception e) {
           System.err.println(e.toString());
    SOAP messsage
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
          <ns1:printLongs soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:TestNS">
             <in6 href="#id0"/>
             <in7 href="#id0"/>
          </ns1:printLongs>
          <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:long" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</multiRef>
       </soapenv:Body>
    </soapenv:Envelope>
    Exception
    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
    faultActor:
    faultNode:
    faultDetail:
         {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
      at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:143)
      at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1031)
      at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
      at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1140)
      at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:238)
      at org.apache.axis.message.RPCElement.getParams(RPCElement.java:386)
      at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:148)
      at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:319)
      at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
      at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
      at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
      at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:450)
      at org.apache.axis.server.AxisServer.invoke(AxisServer.java:285)
      at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:653)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
      at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:301)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      ....

    Dave, not sure if you still are looking for an answer but i hate seeing unreplied posts so i felt i needed to post something. I'm just beginning with this stuff as well so take my suggestions with a grain of salt....or a beer. Anyways, case 2 would show that you are getting your parameters through properly because the "deserialization" errror is targetted towards the soap reply. Most likely you are trying to receive back a none primitive type. :-D i.e. such as the problem that i'm having.
    hope that helps somewhat.
    graeme.

  • How invoke methods in order within the class?

    I want to invoke all the methods of a class (except the constructor) in the order in which they appear within the class. I have been able to do this using the following code:
    Method [] methodArray = this.getClass().getDeclaredMethods();
    for (int i = 1; i < methodArray.length; i++)
    methodArray.invoke(this, null);
    However, according to the javadoc for class Class, getDeclaredMethod, the elements of the Method array "are not in any particular order." So although the elements of the array happened to be in the order I wanted them when I ran the code, it seems that I will not be able to consistently RELY on the Method array to be set up in this way.
    My question is, in view of what I see when I execute the code, is it possible that the javadoc is overly-cautious, and that the Method objects in fact WILL ALWAYS be placed in the array in the order in which they appear in the class, in spite of the javadoc disclaimer?
    Maybe there's a better way to do what I'm trying to do. The reason I want the methods to execute in this order is that each method is a test case for a component I am testing, and I want the test cases to run in the order coded, using the Method array, without having to embed a number within each method name so that the array can be sorted into the desired order. In addition, I don't want to have to add a new method call to my class whenever I add a test case to it. Is this asking too much?

    The reason the Javadocs are full of disclaimers like this is to highlight the fact that there is no specific contract for a certain behaviour. Because Java is cross-platform, results must be predictable, at all times. So if the spec doesn't require a certain order to be enforced, the docs highlight this. Maybe no implementation takes advantage of this, maybe some do, the fact is as you rightly pointed out, you can't rely on it. So it looks like you are back to hard-coding some state that will let you sort the method order.
    Of course, if you are just settingup a test rig to automagically test the code you write, you can take a chance and rely on your implementation on your machine. But don't tell anyone I told you this.

  • Extending object, without calling super constructor

    public class Object1
        byte index;
        public Object1(byte i)
            index = i;
    public class Object2 extends Object1
        private byte j;
        public Object2() {
            super((byte) 0);
        public void setIndex(byte i)
            j = i;
    import java.util.*;
    public class Test1
        private ArrayList<Object1> aList;
        public Test1()
            aList = new ArrayList<Object1>();
        public void run()
            for (byte i = 0; i < 10; i++)
                aList.add(new Object1(i));
        public ArrayList<Object1> getResults()
            return aList;
    import java.util.*;
    public class Test2
        ArrayList<Object1> results;
         * Constructor for objects of class Test2
        public Test2()
            Test1 t1 = new Test1();
            t1.run();
            results = t1.getResults();
        public void run()
            Iterator<Object1> i = results.iterator();
            while (i.hasNext())
                Object2 o2 = (Object2) i.next();
    public class Test3
        public static void main(String[] args)
            Test2 t2 = new Test2();
            t2.run();
    }There are two things with this code that I'm having problems with.
    1. I want to create an object of class Object1 in Test1. That works fine. In Test2 I then want to extract the object from the ArrayList, but since Object2 extends Object1, I want to get an Object2 out from the ArrayList. However with the code above, I get a ClassCastException. If I leave out the cast, I get an incompatible types error.
    2. I want Object2 to be an extension of Object1, that is, with more fields and methods. But I have no need to create an object of class Object2, since I know I already have an ArrayList of Object1. So I want to remove the constructor from Object2, seeing as I won't need it. However, if I remove the super part (which, again, is not needed, as I will already have created my needed objects of class Object1 when I get there, and only need to EXTEND my Object1 objects), I get a cannot find symbol, constructor Object1() error.
    I'm not sure that I can solve problem 2 without using a super. But I am convinced that I must be able to get the Object1 objects out as Object2 instead. I would just like some help with how to do that.

    ThemePark wrote:
    But I am convinced that I must be able to get the Object1 objects out as Object2 instead. I would just like some help with how to do that.Maybe you don't understand how inheritance works. Go read a basic tutorial on inheritance. You can use an Object2 as an Object1, but not an Object1 as an Object2. You either have to create Object2 objects in the first place; or have to make a wrapper class that takes an Object1 and passes things to the Object1 object; and use objects of this wrapper class.

  • Invoking a constructor

    in ibm's tut i found this sentence:
    a constructor can be invoked only from other constructors
    My Q:
    this means you cant invoke a constructor inside itself, or else that you can only incoke a constructor IF you'r inside one?
    thanks in advance

    i guess i got it;
    thanks for helping
    now, i've another Q, pls:
    i got the first class from the same place, and
    created the second in order to see if i understand it
    (the this again)
    class Dot {
    int x, y;
    Dot(int x, int y) {
              this.x = x;
              this.y = y;
    class Z {
    public static void main(String[] args) {
              Dot d = new Dot(16, 17);
              System.out.println(d.x + ", " + d.y);
    }My Q:
    can i say (even in a bit improper way) that the
    this is translated into d, in my
    class?I wouldn't say it that way. Depending on what image you're conjuring up for that, you may be on the right track though.
    When you use "d.x" and "d.y", there's really no "this" involved.
    If you had a method inside Dot void setX(int x) {
        this.x = x;
    } and then called d.setX(42); then while that method is executing, "this" refers to the same object that "d" refers to outside of the method. "d" has some value which is, in essence, the address of an object. That value was copied into "this" when the setX method was invoked.
    When you invoke the constructor, it's a little different. There's still an objet, but at the time the constructor is executing, "d" doesn't point to it yet (okay, technically, it can, but that's a very low-level optimization issue. conceptutally, it's safe to say it doesn't).
    When you called "d.setX" d's value was copied into "this". In the case of the constructor, however, the keywork "new" tells the VM to create an object, initialize its fields, and invoke its constructor. Once the object has been created, its address is copied into "this" for the constructor to use. When the construction operation has been completed, the address of the object is copied into d.

  • Constructor with no parameters

    Greetings,
    What is a constructor with no parameters?
    Just started on my new lab today and most of its going pretty good. Except I can't get the compiler to go past the first part...which pretty much hangs up the rest. My instructions are to create a constructor with no parameters, and after doing some research I thought I did that. Would someone mind taking at look at this and help me understand what I'm not doing? Thanks.
    I'm only suppose to use the three variables that I've already put in, but the first constructor doesn't want to use any of those.
    public class Time
        // instance variables
        private int hour;
        private int minutes;
        private int seconds;
         * Default constructor for objects of class Time.
        public Time()
            Time();
        }

    public class Time {
        private int hour;
        private int minutes;
        private int seconds;
        // no constructor typed
        public static void main(String[] args) {
            Time t1 = new Time();  // OK
            Time t2 = new Time(5, 5, 5); // error
    }This is Ok for t1 because if you do not provide a default (no args) constructor, one will be supplied when it compiles.
    public class Time {
        private int hour;
        private int minutes;
        private int seconds;
        public Time(int h, int m, int s) {
        public static void main(String[] args) {
            Time t1 = new Time();  // error
            Time t2 = new Time(5, 5, 5); // OK
    }Now ok for t2 since you have provided a constrcutor but not ok for t1 as the default constructor will not be provided for you. Default constructor only provided if you do not provide one.
    public class Time {
        private int hour;
        private int minutes;
        private int seconds;
        public Time() {}
        public Time(int h, int m, int s) {
        public static void main(String[] args) {
            Time t1 = new Time();  // OK
            Time t2 = new Time(5, 5, 5); // OK
    }Now both t1 and t2 are ok since both constructors are been supplied.

  • Invoking the main() method of a class within another

    Greetings -
    Can someone tell me what happens when you invoke the main() method of a class from within another class?
    I have a third-party class, designed to be invoked from a command line, that I want to invoke from within a separate class. What appears to be happening is that following the successful execution of the third-party class, the invoking class is terminated as well. That's not the intended behavior I had envisioned. ^_^
    Is there a better way than invoking the main() method? I still need the invoking class to continue executing.
    Thanks!

    Navigate yourself around pitfalls related to the Runtime.exec() method

  • Constructor in my servlet class

    Can i write a constructor in my servlet class inherited from HttpServlet.
    eg:
    class myServlet extends HttpServlet
    myServlet()
    doGet(......)
    }

    And who will call the derived class no args constructor?
    Remember Servlet classes are managed by the container which is responsible for initiating the servlets and calling appropriate life cycle methods. The container initiates the Servlet using the no args constructor. For all practical purposes you would choose the init() method rather than the constructor for initialization logic.
    ram.

Maybe you are looking for

  • All images show darker in PS since CS4

    After installeing CS4, all my images now look darker in PS. They all look at least 20% darker. I still have CS3 installed, and when I look into CS3, they images now also look darker. But when I flip back to Windows, all images look ok. I thought it m

  • Error - Material can no longer be changed

    Hi Experts, We are facing an error in the SRM portal. There is a PO with 4 line items where the GR/IR has been issued for all the 4. Then the user wants to increment the price of the 4th line item and so he deletes the 4th line item and adds a new li

  • Dreamweaver CC 2014.1 is CS5?

    October 6th, 2014, I downloaded and installed  from Adobe CC what I thought was a trial CS6 version (I'm not sure if the CS# applies in Adobe's CC) of Dreamweaver. Displays as 2014.1 release and has references in the, CSS Designer, to CS5. Also the D

  • New to FF-consul errors-need to talk with someone for help PLEASE

    I am brand new to computer and to Mozilla FF.Total i rec'd about 60 error msg ERROR CONSOL. There are so many,I don't know what you need. I use FF 3.6.10 updated 10/1/10. I updated Adobe Flash to 10,0 on 9/29/10. I see that Adobe crashed. I do not un

  • Getting gifs to work in photoshop...?

    I can't seem to save a gif properly. I have imported a small video and I see each image in all the layers and frames (75 to be exact). Now when I go to save it as a (compu serv) Gif, it only seems to save the first image and nothing else - no moving