Generic method - UnmarshalException (ClassNotFoundException)

The mechanism was working fine until I added a generic method to the interface. Now it fails on a call to the new method.
Here's the relevant code: public interface MyServer extends Remote {
    <T extends pub.beans.Bean> T getBeanAs ( Class<T> clazz, int key )
    throws RemoteException;
public final class MyServerImpl implements MyServer {
    public synchronized <T extends pub.beans.Bean> T
                 getBeanAs ( final Class<T> clazz, final int key )
    throws RemoteException {
        Object bean = null;
        if( clazz == AbcBean.class )  {
            Abc obj = getObj( key );
            if( obj != null )  {
                AllBeanTranslator x = new AllBeanTranslator();
                    * Translates an entity bean at the core of obj to external form.
                    * Core Data Object is class AbcDO.
                    * Returned object is class AbcBean.
                bean = x.translateDO( obj.getData() );
        }  else  {  // ...
        return clazz.cast( bean );
class Client  {
   public static void main ( final String[] args )
    throws Exception {
        System.setProperty("java.security.policy", "./security.policy" );
        if( System.getSecurityManager() == null ) {
            System.setSecurityManager(new RMISecurityManager());
        MyServer server = (BseServer)Naming.lookup( "MyServer" );
        AbcBean aBean = server.getBeanAs( AbcBean.class, 48 );
// exception ^^^
}This throws an exception on a class that the Client should know nothing about: AbcDO. The AbcBean hierarchy never references it. Here's the exception stack: Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
     java.lang.ClassNotFoundException: beans.AbcDO
     at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:178)
     at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
     at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
     at $Proxy0.getBeanAs(Unknown Source)
     at Client.main(Client.java:61)
Caused by: java.lang.ClassNotFoundException: beans.AbcDO
     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:247)
     at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:434)
     at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
     at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
     at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
     at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
     at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
     at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
     at java.beans.PropertyChangeSupport.readObject(PropertyChangeSupport.java:478)
     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:597)
     at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
     at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
     at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
     at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
     at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:155)
     ... 4 moreAnother thing that puzzles me: Why no stub? When I saw that I turned on Stub Generation (I'm using Genady's RMI Eclipse Plug-in) but that caused a world of problems so I turned it back off.

Just making them transient isn't the end of the solution, btw,
     * ChangeSupport serializes any serializable listeners.
     * If the listener is serializable but unknown to the codebase
     * causes UnmarshalException so best make these transient.
    protected transient PropertyChangeSupport pcs;
    protected transient VetoableChangeSupport vcs;After de-serialization pcs and vcs are null and of course the listeners are gone. AbcDO class uses events internally so they need to be re-established. Here's what I did, though I can think of at least two other solutions.
  // Normal constructor - not run during de-serialization
  protected AbcDO ( )  { 
      this.pcs = new PropertyChangeSupport( this );
      addPropertyChangeListener( this );
      this.vcs = new VetoableChangeSupport( this );
      addVetoableChangeListener( new AbcValidator() );
      this.SubObj = new SubObj ();
      this.SubObj .addPropertyChangeListener( this );
   * Re-establish transients after de-serialization.
   * Note how much this looks like the ctor.
   * @return this ready to rock again
   * @throws ObjectStreamException
  private Object readResolve ( )  throws ObjectStreamException  {
      this.pcs = new PropertyChangeSupport( this );
      addPropertyChangeListener( this );
      this.vcs = new VetoableChangeSupport( this );
      addVetoableChangeListener( new AbcValidator() );
      if( this.SubObj != null ) // should be impossible - subObj is final
          this.SubObj .addPropertyChangeListener( this );
      return this;
  }     Note that readResolve() may not be appropriate for a non-final class (see Effective Java). Note also that subObj needs its PropertyChangeSupport re-established.

Similar Messages

  • How to create a generic method?

    Hi,
      I am using a std task TS01200205 to create instance for a BOR object. There are 2 key fields. I want to pass these 2 to the ObjectKey field.
    As for as I know, we have to concatenate these two Keyfields and assign it to 'Object Key' parameter.
      How can I concatenate the 2 strings in my Workflow? Is there any std way of doing it?
    Also what is a generic method? How to create it? Can I make use of generic method to achieve this?
    Thanks,
    Sivagami

    If you want to use it in different workflows the best solution is probably to define an interface and define and implement the method there (a nice thing about BOR interfaces is that you can provide an implementation and not just the definition).
    All you then need to do is let your object type(s) implement that interface, which only requires adding the interface since the implementation has been done already.
    However, I am not saying this is a good way of approaching things, I'm just telling you how you can implement what you suggest.

  • [ABAP OO] Generic method get lines

    Hi Experts,
    I am creating a generic method to get the numbers of lines from any table, like below:
    TABNAME type string.
    LINES type i.
    METHOD get_lines_from_any_dbtab.
      DATA lo_tab TYPE REF TO data  .
      CREATE DATA  lo_tab  TYPE TABLE OF (tabname) .
      SELECT *  FROM (tabname)  INTO TABLE lo_tab .
      DESCRIBE TABLE lo_tab LINES lines  .
      CONDENSE lines 
    METHOD.
    I have an error message during the compilation as:
    LO_TAB is not an internal table.
    Any idea ?
    Kind regards.
    Rachid.

    Got it:
      DATA lo_tab TYPE REF TO data  .
      FIELD-SYMBOLS <fs_dbtab>  TYPE ANY TABLE  .
      CREATE DATA  lo_tab  TYPE TABLE OF (tabname).
      ASSIGN lo_tab->* TO <fs_dbtab>  .
      SELECT *  FROM (tabname)  INTO TABLE <fs_dbtab>  .
      DESCRIBE TABLE <fs_dbtab> LINES lines  .
      CONDENSE lines  .

  • StartDrag using Generic method in Actionscript 3

    Hi,
    AS3:
    How to get general id (or) name from xml loaded images. bcoz, i want to drag and drop that images in generic method. Now, i currently used the event.target.name for each one.
    So, code length was too large. See my code below.
    /*********loading images through xml********/
    var bg_container_mc:MovieClip
    var bg_bg_myXMLLoader:URLLoader = new URLLoader();
    bg_bg_myXMLLoader.load(new URLRequest("xml/backgroundimages.xml"));
    bg_bg_myXMLLoader.addEventListener(Event.COMPLETE, processXML_bg);
    function processXML_bg(e:Event):void {
              var bg_myXML:XML=new XML(e.target.data);
              columns_bg=bg_myXML.@COLUMNS;
              bg_my_x=bg_myXML.@XPOSITION;
              bg_my_y=bg_myXML.@YPOSITION;
              bg_my_thumb_width=bg_myXML.@WIDTH;
              bg_my_thumb_height=bg_myXML.@HEIGHT;
              bg_my_images=bg_myXML.IMAGE;
              bg_my_total=bg_my_images.length();
              bg_container_mc = new MovieClip();
              bg_container_mc.x=bg_my_x;
              bg_container_mc.y=bg_my_y;
              ContentHead.addChild(bg_container_mc);
              for (var i:Number = 0; i < bg_my_total; i++) {
                       var bg_thumb_url=bg_my_images[i].@THUMB;
                        var bg_thumb_loader = new Loader();
                       bg_thumb_loader.load(new URLRequest(bg_thumb_url));
                       bg_thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded_bg);
                       bg_thumb_loader.name="bg_load"+i;
                       bg_thumb_loader.addEventListener(MouseEvent.MOUSE_DOWN, bg_down)
                       bg_thumb_loader.x = (bg_my_thumb_width-18)*bg_x_counter;
                       bg_thumb_loader.y = (bg_my_thumb_height-45)*bg_y_counter;
                       if (bg_x_counter+1<columns_bg) {
                                 bg_x_counter++;
                       } else {
                                 bg_x_counter=0;
                                 bg_y_counter++;
    function thumbLoaded_bg(e:Event):void {
              var my_thumb_bg:Loader=Loader(e.target.loader);
             var sprite:Sprite = new Sprite();
              var shape:Shape = new Shape();
              shape.graphics.lineStyle(1, 0x0098FF);
              shape.graphics.drawRect(e.target.loader.x-2, e.target.loader.y-2, e.target.loader.width+4, e.target.loader.height+4);
              sprite.addChild(shape);
              sprite.addChild(my_thumb_bg);
              sprite.x=4;
              bg_container_mc.addChild(sprite);
              my_thumb_bg.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoaded_bg);
    //  get name for each image. 
    I want to change this code in generic method. do needful.
    function bg_down(event:MouseEvent):void {
              var bg_name:String=new String(event.currentTarget.name);
              var bg_load:MovieClip=event.currentTarget as MovieClip;
              if (event.currentTarget.name=="bg_load0") {
                      var alaska_mc:alaska_png=new alaska_png();
                       addChild(alaska_mc);
                       alaska_mc.x=stage.mouseX;
                       alaska_mc.y=stage.mouseY;
                       alaska_mc.name="alaska_duplicate"+alaska_inc;
                       alaska_inc++;
                       alaska_mc.startDrag(false);
                      alaska_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
                       alaska_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load1") {
                       var lake_mc:lake_png=new lake_png();
                       addChild(lake_mc);
                       lake_mc.x=lake_mc.mouseX;
                       lake_mc.y=lake_mc.mouseY;
                       lake_mc.name="lake_duplicate"+lake_inc;
                       lake_inc++;
                       lake_mc.startDrag(false);
                       lake_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load2") {
                       var mountn_mc:mountn_png=new mountn_png();
                       addChild(mountn_mc);
                       mountn_mc.x=mountn_mc.mouseX;
                       mountn_mc.y=mountn_mc.mouseY;
                       mountn_mc.name="mountn_duplicate"+mountn_inc;
                       mountn_inc++;
                       mountn_mc.startDrag(false);
                       mountn_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load3") {
                       var town_mc:town_png=new town_png();
                       addChild(town_mc);
                       town_mc.x=town_mc.mouseX;
                       town_mc.y=town_mc.mouseY;
                       town_mc.name="town_duplicate"+town_inc;
                       town_inc++;
                       town_mc.startDrag(false);
                       town_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load4") {
                       var water_mc:water_png=new water_png();
                       addChild(water_mc);
                       water_mc.x=water_mc.mouseX;
                       water_mc.y=water_mc.mouseY;
                       water_mc.name="water_duplicate"+water_inc;
                       water_inc++;
                       water_mc.startDrag(false);
                      water_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load5") {
                       var city_mc:city_png=new city_png();
                       addChild(city_mc);
                       city_mc.x=city_mc.mouseX;
                       city_mc.y=city_mc.mouseY;
                       city_mc.name="city_duplicate"+city_inc;
                       city_inc++;
                       city_mc.startDrag(false);
                      city_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load6") {
                        var citywide_mc:citywide_png=new citywide_png();
                       addChild(citywide_mc);
                       citywide_mc.x=citywide_mc.mouseX;
                       citywide_mc.y=citywide_mc.mouseY;
                       citywide_mc.name="citywide_duplicate"+citywide_inc;
                       citywide_inc++;
                       citywide_mc.startDrag(false);
                      citywide_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load7") {
                       var downtown_mc:downtown_png=new downtown_png();
                       addChild(downtown_mc);
                       downtown_mc.x=downtown_mc.mouseX;
                       downtown_mc.y=downtown_mc.mouseY;
                       downtown_mc.name="downtown_duplicate"+downtown_inc;
                       downtown_inc++;
                       downtown_mc.startDrag(false);
                      downtown_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load8") {
                       var powerlines_mc:powerlines_png=new powerlines_png();
                       addChild(powerlines_mc);
                       powerlines_mc.x=powerlines_mc.mouseX;
                       powerlines_mc.y=powerlines_mc.mouseY;
                       powerlines_mc.name="powerlines_duplicate"+powerlines_inc;
                       powerlines_inc++;
                       powerlines_mc.startDrag(false);
                      powerlines_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load9") {
                       var tropical_mc:tropical_png=new tropical_png();
                       addChild(tropical_mc);
                       tropical_mc.x=tropical_mc.mouseX;
                       tropical_mc.y=tropical_mc.mouseY;
                       tropical_mc.name="tropical_duplicate"+tropical_inc;
                       tropical_inc++;
                       tropical_mc.startDrag(false);
                      tropical_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
              if (event.currentTarget.name=="bg_load10") {
                       var waters_mc:waters_png=new waters_png();
                       addChild(waters_mc);
                       waters_mc.x=waters_mc.mouseX;
                       waters_mc.y=waters_mc.mouseY;
                       waters_mc.name="waters_duplicate"+waterthumb_inc;
                       waterthumb_inc++;
                       waters_mc.startDrag(false);
                      waters_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
    Please suggest me if any  one.
    Regards,
    Viji. S

    Post AS3 questions in the AS3 forum, not the AS1/2 forum.

  • Doubt about generic method

    i have a generic method has shown below
    public static <E extends Number> <E>process(E list){
    List<Interger> output = new ArrayList<Interger>(); or List<Number> output = new ArrayList<Number>();
    return output ;
    if delcare the output variable using Interger or Number . when i am returning the output . it is showing me compiler error and it suggests me to add cast List<E>. Why i not able understand. please clarify my doubt.
    Thanks
    Sura.Maruthi
    Edited by: sura.maruthi on Sep 21, 2008 9:48 PM

    Your method declaration is garbled; there can be only one <...> clause, eg
    public static <E extends Number> E process(E list);This declaration says that for any subclass E of Number, the method process takes a single E instance (called list!?) and returns a single E instance. A valid implementation would be
    return list;I'm guessing you want the parameter to have type List<E>?. Like this:
    public static <E extends Number> E process(List<E> list);This declaration says that for any subclass E of Number, the method process takes a list of E's and returns a single E instance. A valid implementation would be
    return list.get(0);Or perhaps you also want to return a list of numbers?
    public static <E extends Number> List<E> process(List<E> list);This declaration says that for any subclass E of Number, the method process takes a list of E's and returns another list of E's. A valid implementation would be
    return list;Note that you cannot just return a list of Integers or Floats, because your generic method must work for any subclass of Number, and you're promising to return back a list of the same type as the argument passed in.
    Edited by: nygaard on Sep 22, 2008 10:05 AM

  • Doubt regarding Generic methods

    I have 4 generics Methods getEJBHome,getEJBLocalHome ,findEJBLocalHomeAndPopulateCache,findEJBHomeAndPopulateCache
         public <T extends EJBHome> T getEJBHome(final String jndiName,final Class<T> ejbHomeClass) throws NamingException,ClassCastException{
              T ejbHome=null;
              try{
                   if(serviceLocatorCache.containsKey(jndiName)){
                        ejbHome=(T)serviceLocatorCache.get(jndiName);     
                   else{
                        ejbHome=findEJBHomeAndPopulateCache(jndiName,ejbHomeClass);
              catch(NamingException namingException ){
                   System.err.println("Exception in getEJBHome ["+namingException.getMessage()+"]");
                   throw namingException;
              catch(ClassCastException classCastException ){
                   System.err.println("Exception in getEJBHome ["+classCastException.getMessage()+"]");
                   throw classCastException;
              return ejbHome;
         private <T extends EJBHome> T findEJBHomeAndPopulateCache(final String jndiName,final Class<T> ejbHomeClass) throws NamingException{
              T ejbHome=null;
              try{
                   ejbHome=(T)javax.rmi.PortableRemoteObject.narrow(context.lookup(jndiName),ejbHomeClass);
                   serviceLocatorCache.put(jndiName,ejbHome);
              catch(NamingException namingException){
                   System.err.println("Exception in findEJBHomeAndPopulateCache ["+namingException.toString()+"]");
                   throw namingException;
              return ejbHome;
         }i am calling findEJBHomeAndPopulateCache like normal method call,When i try to call findEJBLocalHomeAndPopulateCache from getEJBLocalHome it shows compile time error .
         public <T extends EJBLocalHome> T getEJBLocalHome(final String jndiName) throws NamingException{
              T ejbLocalHome=null;
              try{
                   if(serviceLocatorCache.containsKey(jndiName)){
                        ejbLocalHome=(T)serviceLocatorCache.get(jndiName);     
                   else{
                        ejbLocalHome=this.<T>findEJBLocalHomeAndPopulateCache(jndiName);
                        //ejbLocalHome=findEJBLocalHomeAndPopulateCache(jndiName); ERROR
              catch(NamingException namingException ){
                   System.err.println("Exception in getEJBLocalHome ["+namingException.getMessage()+"]");
                   throw namingException;
              catch(Exception exception ){
                   System.err.println("Exception in getEJBLoacalHome ["+exception.getMessage()+"]");
                   throw new NamingException("Exception in getEJBLoacalHome ["+exception.getMessage()+"]");
              return ejbLocalHome;
         }when i try to call method findEJBLocalHomeAndPopulateCache like ejbLocalHome=findEJBLocalHomeAndPopulateCache(jndiName);
    i am getting compile time error
    ServiceLocator.java:133: type parameters of <T>T cannot be determined; no unique maximal instance ex
    ists for type variable T with upper bounds T,javax.ejb.EJBLocalHome
        [javac]                             ejbLocalHome=findEJBLocalHomeAndPopulateCache(jndiName);
        [javac]     ^
    when i am calling that method like
    this.<T>findEJBLocalHomeAndPopulateCache(jndiName); it is not showing any error.normally we are invoking generic methods like normal methods ?
    Why i am getting a compile time error for findEJBLocalHomeAndPopulateCache method?
    method findEJBLocalHomeAndPopulateCache is as shown
         private <T extends EJBLocalHome> T findEJBLocalHomeAndPopulateCache(final String jndiName) throws NamingException{
              T ejbLocalHome=null;
              try{
                   ejbLocalHome=(T)context.lookup(jndiName);
                   serviceLocatorCache.put(jndiName,ejbLocalHome);
              catch(NamingException namingException){
                   System.err.println("Exception in findEJBLocalHomeAndPopulateCache ["+namingException.toString()+"]");
                   throw namingException;
              return ejbLocalHome;
         }Plz help

    Hi Ben,
    Thanks for your replay, Can you please tell me why in first case ie getEJBHome method call findEJBHomeAndPopulateCache(jndiName,ejbHomeClass) not causing any error.In both case upper bound of ‘T’ is EJBLocalHome .Kindly give me a clear idea.
    Plz help

  • Generic method signatures

    I've searched but can't find that a question I have has been asked (or answered). I apologize in advance if it has. Here is my question.
    In Java Generics FAQ by Angelika Langer states in FAQ 802 ( [http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ802] ) "the type parameters of a generic method including the type parameter bounds are part of the method signature."
    In FAQ 810, many examples are presented of method declarations, including generic ones, and their corresponding method signatures. For example,
    <T> T method(T arg) has the following signature in the example:
    <$T1_extends_Object>method($T1_extends_Object>)
    It would seem to be intuitively clear that the type parameter and bounds would be part of the method signature but I can't seem to find such a stipulation/requirement of such in the Java Language Specification. Anybody know where it's stipulated in the JLS?
    Best Regards

    user13143654 wrote:
    Yeah, I know. The title of the subsection is "Determining Method Signature," but then it never seems to expressly do that other than in some ephemeral wafting byproduct of overload resolution.I wouldn't call it "ephemeral" and "wafting." It's pretty specific. If you're looking for the $T1_extends_Object notation, you won't find it. That's not part of the spec.
    I can't seem to find a specific spot in the subsection where I can say "OK, now I've got the method signature and now can proceed to ..." Well, it goes on to Phase 3, and then on to 15.12.2.5 Choosing the Most Specific Method. I'm not sure what you're looking for. It does describe in detail how we get from all the methods in the universe, to which type's methods we'll be considering to which signatures could match to which one is the best match. I don't know what else you're looking for.
    If you're looking for somebody to digest, translate, and simplify all that for you, good luck, but it ain't gonna be me. :-)
    If you have specific questions about smaller pieces of it I (or somebody else) might be able to help out. At the moment though, your question is rather vague.
    Edited by: jverd on May 3, 2011 1:48 PM

  • Generic  method to execue procedure

    Hi I was wondering if there was a way to write a generic method to execute a stored procedure in my EJB. I was thinking of the input parameters as being the data source, procedure name, and an array of parameters. I'm new to java and therefore I didn't know if I should be using a callable statement for prepared statement for this. Also how to get around the problen of knowing my datatype when trying to set parameters for a statement since each parameters expects you to provide a specific set method for data type.
    V

    Whoops sorry about the half broken code.
    javax.naming.InitialContext ctx = new javax.naming.InitialContext();
    javax.sql.DataSource ds =                    (javax.sql.DataSource) ctx.lookup("jdbc/sybase");
    conn = ds.getConnection();
    cstmt =     conn.prepareCall(
              "{call dbo.ModifyExchange (?,?,?,?,?,?,?,?,?,?,?,?)}");
    cstmt.setObject(1, (Object) inputs[0]);
    cstmt.setObject(2, (Object) inputs[1]);               
    cstmt.setObject(3, (Object) inputs[2]);
    cstmt.setObject(4, (Object) inputs[3]);
    cstmt.setObject(5, (Object) inputs[4]);
    cstmt.setObject(6, (Object) inputs[5]);
    cstmt.setObject(7, (Object) inputs[6]);
    cstmt.setObject(8, (Object) inputs[7]);
    cstmt.setObject(9, (Object) inputs[8]);
    cstmt.setObject(10,(Object) inputs[9]);
    cstmt.setObject(11,(Object) inputs[10]);
    cstmt.setObject(12,(Object) inputs[11]);
    System.out.println("ExecuteUpdate Beginning");
    result = cstmt.executeUpdate();
    When I execute it I get "com.sybase.jdbc2.jdbc.SybSQLException: Implicit conversion from datatype 'VARCHAR' to 'TINYINT' is not allowed. Use the CONVERT function to run this query."
    Any ideas?

  • Generic method specialization

    I discovered today that it is possible overload a generic method with a non-generic one. Sounds reasonable, but I hadn't thought about it:
    class Util {
      public static <T> boolean isEmpty(T t) {
        return t == null;
      public static boolean isEmpty(String s) {
        return s == null || s.trim().equals(""");
      public static <A extends HasEmptyTest> boolean isEmpty(A a) {
        //class HasEmptyTest declares method isEmpty
        return a == null || a.isEmpty();
    }My question: Do you consider this in good style or feature abuse?
    Thanks for your response,

    Since generic methods may be substituted with their "erased" variants, your question boils down to this, totally non-generic, question:
    Is it advisable to overload a method with an argument of type A with a version that has an argument of type B when a widening conversion exists from A to B or vice versa?
    I'd answer: No, it's not advisable. It may lead to surprising behaviour.

  • Generic method

    Hi all,
    i have a question related to generic method in a non-generic class.
    the following code cannot be compiled. but I don't know why.
    public class G
           void print(Integer i)
              System.out.println("Inte");
         void print(String s)
              System.out.println("String");     
            <T> void callprint(T t)
              print(t);
            public static void main(String args[])
                    G g = new G();
                    g.callprint(new Integer(5));
    }Edited by: 812302 on Nov 16, 2010 6:58 PM
    Edited by: 812302 on Nov 16, 2010 6:59 PM

    Did you bother to read the error message. I'm sure it says something about not finding the print method and nothing to do with Generics. BTW you use square brackets for code tags or before and after your code.                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Generic method signature help

    Hello All,
    I'm confused about the following generic method signature . Compilation fails
    public class Animal{}
    public class Dog extends Animal{}
    public <E super Dog> List<E> methodABC(List<E> list){
    The compiler gives the following error
    E cannot be resolved to a type
    E cannot be resolved to a type
    Syntax error on token "super", , expected
    if i change the declaration of E to <E extends Dog>, no compiler error.
    An early response will be highly appreciated. Thanks in advance.
    Kind Regards.
    Hasnain Javed Khan.

    you cannot use "super" on a type variable, only on wildcards

  • How do I gain type safety with a generic method taking a class object?

    How do I achieve type safety with the following code without getting a compile error?
    import java.util.ArrayList;
    import java.util.List;
    public class Main {
        public static void main(String[] args) throws Exception {
            ListenerHolder th = new ListenerHolder();
            List<TestObject<String>> list = createTestObjectList();
            /* *** compiler error here *** */
            th.addListener(TestObject.class, list);
        private final static List<TestObject<String>> createTestObjectList() {
            List<TestObject<String>> list = new ArrayList<TestObject<String>>();
            return list;
        private final static class ListenerHolder {
                /* *** my generic method *** */
                public <T> void addListener(Class<T> listenerType, List<T> listener) { }
        private final static class TestObject<T> { }
    }The compiler error is:
    C:\java\Main.java:11: <T>addListener(java.lang.Class<T>,java.util.List<T>) in Main.ListenerHolder cannot be applied to (java.lang.Class<Main.TestObject>,java.util.List<Main.TestObject<java.lang.String>>)
    Thanks in advance,
    Dan

    dandubois wrote:
    Thanks for the help, that is exactly what I wanted to know.
    It didn't occur to me that TestObject<T> would in some respects be considered as an 'extends' of TestObject as I know the compiler converts them all back to plain TestObjects.Maybe I should have written TestObject<?>, to make it more obvious. There's some supertype/subtype relation diagram in the Generics FAQ somewhere, if you need more detailed information.
    In the end, I think jtahlborn's solution might be more appropriate in the described scenario, so you should go for it.

  • Generic method and wildcards

    Suppose I have this simplified code to do dynamic mapping between specific classes. My question is: the addItem and getItem functions
    are pretty similar however addItem compiles fine and getItem raises compilation error:
    Type mismatch: cannot convert from Class<capture#5-of ? extends List<? extends Object>> to Class<P>
         private Map<Class<? extends Object>,
         Class<? extends List<? extends Object>>> map =
              new HashMap<Class<? extends Object>,
              Class<? extends List<? extends Object>>>();
         public Test() {
              getItem(Object.class);
         public <T extends Object, P extends List<T>> void addItem(Class<T> clz, Class<P> list) {
              map.put(clz, list);
         public <T extends Object, P extends List<T>> Class<P> getItem(Class<T> clz) {
              return map.get(clz);
         }

    Sergey_M. wrote:
    OK, thank you for the response. Then the actual question is how to achieve this functionality:
    1)Store mapping between two referenced classes, for example, Class<? extends MyClass> and Class<? extends List<? extends MyClass>>.
    I mean if we have class MyClass then pair will be (MyClass.class, MyList.class) where MyList implements List<MyClass>.The way you were doing it is fine.
    2)Provide generic method to get second class by supplying the first one.You can do this fine, but the exact type of list will of course be unknown by the calling code (if it knew the type of list it needed, why bother calling getItem in the first place?).
    Just change your method to:
    public <T extends Object> Class<? extends List<?>> getItem(Class<T> clz) {
              return map.get(clz);
         }And by then even the T is not needed, just use:
    public Class<? extends List<?>> getItem(Class<?> clz) {
       return map.get(clz);
    }I am fairly, but not fully sure that you never need <? extends Object>, as that is always just a more verbose way of saying <?>.

  • Are bridge methods generated for generic methods?

    I've recently come across the notion of bridge methods. They provide type safety while allowing for erasure. However, the only places where they've been mentioned is with your class extending a parameterized type. That is the only case mentioned with bridge methods in the JLS as well as:
    http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#Under which circumstances is a bridge method generated?
    So I've been wondering about generic methods. For example, Collections.max's signature looks like the following in the source:
    public static <T extends Object & Comparable<? super T>> T max(Collection<T> coll)
    and after erasure:
    public static Object max(Collection coll)
    However, one cannot simply pass any type of Collection to the max method, it must implement Comparable and whatnot. Therefore, my question is how does it do that? Mustn't there be some sort of bridge method or generic information in the class file? Else how can the compiler, by just looking at the erasure of generic methods, check type safety, do capture conversion, type inference, etc?

    Generic information is erased from the byte code. It is still there in the class file in the method signatures. That's how the compiler knows.

  • Java.lang.AssertionError: Can not find generic method public abstract

    I just downloaded the JDev 11g and trying to test the JEE web app. Below is my install:
    JDeveloper 11g
    JEE Web Project
    EJB 3.0
    Steps taken:
    1. Created an entity bean from a table.
    2. Created a session facade
    3. Create sample Java client to use the facade (Right-click on the session facade, and choose New sample Java Client from the context menu)
    4. Run the session facade
    5. Run the Java client
    I got the following error.
    java.lang.AssertionError: Can not find generic method public abstract java.util.List<com.oracle.orm.model.ejb.persistence.Hosttags> queryHosttagsFindAll() in EJB Object
    I checked the methods in the beans and interfaces, they are all there. Any idea?
    Thanks.

    I have a customer that has this problem.
    We wrote me that:
    we got a java.lang.NoSuchMethodException while the method exist even in the generated (by WLS) stub.
    when we change the interface by putting a "list" instead of list <> then it works.
    hope it can help, but should be great know why.
    Regards
    Marco
    글 수정: user10649412

Maybe you are looking for

  • Can't add rows to a table in Pages 5.1

    I started my table in Numbers but it defaults to huge margins top bottom and on the sides so I can't get much on one page and it won't let you change the margins - one of the huge advantages Excel has. So I copied and pasted part of my table into Pag

  • Files not shown in Catalog

    I am in the process of moving files from one Hard Drive to another, both in the LR Catalog.  The files shows in Explorer but not in the Lightroom Folder.  When I try to move the same file from one LR folder to another folder on a different drive but

  • Deleting the Contacts File

    My contacts file is a disaster. How can I delete it in its entirety and Load a clean file from my PC? Post relates to: Zire 31 Message Edited by boxturtle on 12-16-2009 01:23 PM

  • Getting error as Buffer table not up to date while checking EBP order

    Hi SRM gurus, We have one order which is created in the EBP side and the same is replicated in the backend also. Also confirmations and invoices are posted for this local PO. These confirmations and invoices are also carried over to backend. However

  • Confirmed Quantity not displayed in SO

    Hi All, Recently we went live on ECC 6.0 and now we are using APO for availability. We have an issue: A sales order contains 5 line items. The first line item is confirmed for Feb mid. the other items are not confirmed while creating the SO. User lat