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

Similar Messages

  • 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

  • Doubt: About synchronized methods?

    Hi,
    Can any one let me know, Is there any difference between static and non-static synchronized methods? If yes, what is the difference?

    One is static and one isn't. What did you think?
    As I recall, non-static methods lock on the object, whereas static methods lock on the class object, if that's what you're wondering about.

  • Technical doubt about setBounds() method

    Hi all.
    I have a little doubt. I don't completely understand the behaviour of setBounds() method of a JComponent extending class.
    I prepared a little test application to explain this doubt. Here it is:
    import javax.swing.*;
    import java.awt.*;
    public class TestSetBounds extends JFrame{
        JPanel myPanel = new JPanel();
        MyComponent myComp = new MyComponent();
        public TestSetBounds() {
            super("SetBounds Test");
            setSize(480, 320);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myPanel.add(myComp);
            setContentPane(myPanel);
            setVisible(true);
        public static void main(String args[]) {
            TestSetBounds tsb = new TestSetBounds();
    class MyComponent extends JComponent implements Runnable
        // setting dimension properties
        int compWidth = 25;
        int compHeight = 50;
        // these values are for testing
        int xStart = 490;
        int xEnd = -12;
        Thread t;
        public MyComponent()
            super();
            setOpaque(true);
            setVisible(true);
            if (t == null)
                t = new Thread(this);
                t.start();
        public void paintComponent(Graphics g)
            super.paintComponents(g);
            setBounds(xStart, 160, compWidth, compHeight);
            Graphics2D area2D = (Graphics2D) g;
            area2D.setColor(Color.RED);
            area2D.fillRect(0, 0, compWidth, compHeight);
        public Dimension getPreferredSize() {
          return new Dimension(compWidth, compHeight);
        public Dimension getMaximumSize() {
          return getPreferredSize();
        public void run()
            for(   ; xStart > xEnd; xStart--)
                repaint();
                try
                    {t.sleep(10);}
                catch (Exception exc) {}
    }   I tested two situations:
    a. Setting xStart = 100 and xEnd = -12, the application run how I expected. With negative value of x coordinate, my component is painted starting out of panel. We only can see my component portion which remains on the panel.
    b. Setting xStart = 490 and xEnd = 300. My component is initially painted out of panel, like test a. During for-cicle, xStart value decreases, entering the panel width value. At this point I must see the component portion which remain on the panel.But the component seems not be painted.
    Why this behaviour?
    Thanks,
    Massimiliano

    Your immediate problem can be solved by making two changes:
    a) your component has no initial size:
    setSize(25, 50); // this is new
    setOpaque(true);
    setVisible(true); // not requiredb) use setLocation() to reposition the component
    setLocation(xStart, 160);
    //repaint(); // not required since changing the location will cause a repaintHowever the code still has many areas of concern.
    For example, after the component has stopped moving, resize the frame. Notice how the component jumps to the top and middle of the frame? This is because by default a JPanel uses a LayoutManager. When you resize the frame the LayoutManager is invoked and the component is positioned based on the rules of the LayoutManager.
    So, you need to read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html]Using Layout Manager to understand the difference between using a Layout Manager and using "Absolute Positioning" (which is what you are attempting to do).
    You should not be altering the "size" or "location" of the component in the paintComponent() method (ie. get rid of the setBounds()). These changes should be done externally as we did by using the setLocation(..) method.
    When you fill the rectangle you should just use getSize().width and getSize().height, instead of your hard coded variables. Then you can dynamically change the size of your component by using the setSize() method.
    The size of the component should not be hard coded. Once you've made the above change you can simply do:
    MyComponent component = new MyComponent();
    component.setSize(25, 50);

  • Doubt about generic delta using function module.

    Hi,
    I have the following scenario.
    I have to create a generic data source having delta using funcation module.
    The full load works fine, but the delta load not.
    I don't know, if always the field that was specified as a delta, must be part of the cursor in this case AFRU~LAEDA
    This is my cursor:
    OPEN CURSOR WITH HOLD S_CURSOR FOR
               SELECT AFIHAUFNR AFIHADDAT AFIHIPHAS AFIHILART AFIH~AKKNZ
                             AFIHPLKNZ AFIHILOAN AFIHIWERK AS ZPLANPLANT AFIHEQUNR
                             ILOA~TPLNR
                             AFKOGSTRP AFKOGLTRP AFKOGSTRS AFKOGLTRS AFKOGSTRI AFKOGETRI AFKO~FTRMI
                             AUFKAEDAT AUFKERDAT AUFKWERKS AUFKKOSTL AUFKKOKRS AUFKSOWRK AUFK~OBJNR
                             AUFKAUART AUFKVAPLZ
                             CRHD~ARBPL
                            TKA01~WAERS AS ZCOSTP_ML_UM
                  FROM AFIH
                       INNER JOIN AFKO ON AFIHAUFNR = AFKOAUFNR
                       LEFT OUTER JOIN ILOA ON ILOAILOAN = AFIHILOAN
                       INNER JOIN AUFK ON AFIHAUFNR = AUFKAUFNR
                       INNER JOIN TKA01 ON AUFKKOKRS = TKA01KOKRS
                       LEFT OUTER JOIN CRHD ON CRHDOBJID = AFIHGEWRK
                  WHERE AFIH~AUFNR in L_R_AUFNR
                        AND AFIH~EQUNR in L_R_EQUNR
                        GROUP BY AFIHAUFNR AFIHADDAT AFIHIPHAS AFIHILART AFIHAKKNZ AFIHPLKNZ AFIH~ILOAN 
                                           AFIHIWERK AFIHEQUNR
                                          ILOA~TPLNR
                                          AFKOGSTRP AFKOGLTRP AFKOGSTRS AFKOGLTRS AFKOGSTRI AFKOGETRI AFKO~FTRMI
                                          AUFKAEDAT AUFKERDAT AUFKWERKS AUFKKOSTL AUFKKOKRS AUFKSOWRK 
                                         AUFKOBJNR AUFKAUART AUFK~VAPLZ
                                         CRHD~ARBPL
                                         TKA01~WAERS.
    For each aufnr I must go to the afru table and totalize the real work (IWNW)  and real duration (IDAUR) when AFRUSTZHL > 0 and totalize too when AFRUSTZHL = 0 but with sign to negative.
    This is my external query, i need that the field AFRU~LAEDA must be taken as delta field:
              SELECT AFRUERSDA AFRULAEDA AFRUSTZHL SUM( AFRUISMNW ) AS ZTRA_REAL AFRUISMNE AS ISMNE SUM( AFRUIDAUR ) AS ZDURAC_REAL AFRU~IDAUE AS IDAUE
                     INTO CORRESPONDING FIELDS OF TABLE WT_AFRU_OM
              FROM AFRU
                   WHERE AUFNR = WT_ZCUROM-AUFNR
                         AND AFRU~STZHL = 0
                   GROUP BY AFRUERSDA AFRULAEDA AFRUSTZHL AFRUAUFNR AFRUISMNE AFRUIDAUE AFRUISMNW AFRUIDAUR
                   order by AFRUERSDA AFRULAEDA AFRUSTZHL AFRUIDAUE AFRU~ISMNE.
              IF sy-subrc = 0.
                CLEAR WT_AFRU_OM2.
                REFRESH WT_AFRU_OM2.
                SELECT AFRUERSDA AFRULAEDA AFRUSTZHL SUM( AFRUISMNW ) AS ZTRA_REAL AFRUISMNE AS ISMNE SUM( AFRUIDAUR ) AS ZDURAC_REAL AFRU~IDAUE AS IDAUE
                       INTO CORRESPONDING FIELDS OF TABLE WT_AFRU_OM2
                FROM AFRU
                     WHERE AUFNR = WT_ZCUROM-AUFNR
                           AND AFRU~STZHL > 0
                     GROUP BY AFRUERSDA AFRULAEDA AFRUSTZHL AFRUAUFNR AFRUISMNE AFRUIDAUE AFRUISMNW AFRUIDAUR
                     order by AFRUERSDA AFRULAEDA AFRUSTZHL AFRUIDAUE AFRU~ISMNE.
                IF sy-subrc = 0.
                  LOOP AT WT_AFRU_OM2.
                    WT_AFRU_OM2-ZTRA_REAL = WT_AFRU_OM2-ZTRA_REAL * -1.
                    WT_AFRU_OM2-ZDURAC_REAL = WT_AFRU_OM2-ZDURAC_REAL * -1.
                    APPEND WT_AFRU_OM2 TO WT_AFRU_OM.
                  ENDLOOP.
                ENDIF.
                LOOP AT WT_AFRU_OM.
                  "fjro incluir el clear y el move
                  CLEAR WT_DATOS_OM.
                  MOVE-CORRESPONDING W_DATOS_BASE to WT_DATOS_OM.
                  MOVE-CORRESPONDING WT_AFRU_OM TO WT_DATOS_OM.
                  APPEND WT_DATOS_OM.
                  APPEND WT_DATOS_OM TO WT_ESTFIN_OM.
                ENDLOOP.
              ENDIF.
    It's possible set the delta field in a external query of the cursor.
    Best Regards
    Ramon Sanchez
    Edited by: RAMON SANCHEZ on Aug 20, 2010 2:46 PM

    Hi Sri,
    here some coding, I hope this helps!
    first, get the delta-field
          LOOP AT s_s_if-t_select INTO l_s_select.
            CASE l_s_select-fieldnm.
              WHEN 'ZDATE'.
                MOVE-CORRESPONDING l_s_select TO r_date.
                IF r_date-high IS INITIAL OR r_date-high = space.
                  r_date-high = '9991231'.
                ENDIF.
                APPEND r_date.
            ENDCASE.
          ENDLOOP.
    Cursor öffnen
          OPEN CURSOR WITH HOLD s_cursor FOR
          SELECT * FROM
          WHERE  ....
          AND    erdat in r_date
          AND    aedat IN r_date.
          FETCH NEXT CURSOR s_cursor INTO CORRESPONDING FIELDS OF table e_t_data package size s_s_if-maxsize.
    regards
    Siggi
    PS: Note that this coding only works for a very straight forward extraction.
    Message was edited by: Siegfried Szameitat

  • Doubt about dispose() method of JDialog

    Hi guys,
    Consider the following code:
              MyDialog dialog = new MyDialog(parent);
              dialog.setVisible(true);
                    // may the dialog was disposed before the following line gets executed
              dialog.getVariableValue();
              dialog.dispose();Suppose the MyDialog extends JDialog and have a member variable which can be accessed by getVariableValue() method.
    A dialog appears, enter something which is stored by a member variable of the MyDialog class. Then close the dialog by invoking dispose() method. After the dialog disappears, the next line dialog.getVariableValue() can get the entered value.
    I thought that the dialog will be null after dispose() gets called, but actually not.
    Is the current thread stopped at the line dialog.setVisible(true) and wait for the dialog to be closed?
    Can anyone explain?

    depends if you are to check isDisplayable() after myContainer = nullbut my output would be still
    run:
    100
    LoopsNo1
    There is JFrame
    LoopsNo2
    There is JFrame
    LoopsNo3
    There is JFrame
    LoopsNo4
    There is JFrame
    System Exit
    100
    100
    100
    100
    100
    100
    BUILD SUCCESSFUL (total time: 13 seconds)from code
    import java.awt.Dialog;
    import java.awt.Frame;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JWindow;
    import javax.swing.SwingUtilities;
    public class WindowGCDemo {
        private javax.swing.Timer timer = null;
        private int count = 0;
        public WindowGCDemo() {
            JFrame myFrame = new JFrame();
            for (int i = 0; i < 99; i++) {
                JWindow jWindow = new JWindow(myFrame);
                jWindow.setSize(200, 400);
                jWindow.setVisible(true);
                //jWindow = null;
            start();
            System.out.println(JWindow.getWindows().length); // prints 100
        private void start() {
            timer = new javax.swing.Timer(3000, updateCol());
            timer.start();
        private void startAgain() {
            timer = new javax.swing.Timer(3000, updateColAgain());
            timer.start();
        public Action updateCol() {
            return new AbstractAction("Set Delay") {
                private static final long serialVersionUID = 1L;
                @Override
                public void actionPerformed(ActionEvent e) {
                    timer.stop();
                    Window[] wins = Window.getWindows();
                    for (int i = 0; i < wins.length; i++) {
                        if (wins[i] instanceof JWindow) {
                            wins.setVisible(false);
    wins[i].dispose();
    wins[i] = null;
    System.gc();
    count++;
    startAgain();
    public Action updateColAgain() {
    return new AbstractAction("Set Delay") {
    private static final long serialVersionUID = 1L;
    @Override
    public void actionPerformed(ActionEvent e) {
    System.out.println("LoopsNo" + count);
    Window[] wins = Window.getWindows();
    for (int i = 0; i < wins.length; i++) {
    if (wins[i] instanceof JWindow) {
    } else if (wins[i] instanceof JFrame) {
    System.out.println("There is JFrame");
    } else if (wins[i] instanceof JDialog) {
    System.out.println("There is JFrame");
    } else if (wins[i] instanceof JWindow) {
    System.out.println("There is JWindow");
    wins[i].setVisible(true);
    } else {
    System.out.println("There is something else");
    count++;
    startAgain();
    if (count > 4) {
    timer.stop();
    stop();
    private void stop() {
    System.out.println("--------------------------------------------");
    System.out.println("System Exit");
    System.out.println(JFrame.getWindows().length);
    System.out.println(JDialog.getWindows().length);
    System.out.println(JWindow.getWindows().length);
    System.out.println(Frame.getWindows().length);
    System.out.println(Dialog.getWindows().length);
    System.out.println(Window.getWindows().length);
    System.exit(0);
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
    WindowGCDemo windowGCDemo = new WindowGCDemo();
    }Edited by: mKorbel on 18.9.2011 23:30 typos                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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.

  • 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.

  • Doubt about  a null value assigned to a String variable

    Hi,
    I have a doubt about a behavior when assigning a null value to a string variable and then seeing the output, the code is the next one:
    public static void main(String[] args) {
            String total = null;
            System.out.println(total);
            total = total+"one";
            System.out.println(total);
    }the doubt comes when i see the output, the output i get is this:
    null
    nulloneA variable with null value means it does not contains a reference to an object in memory, so the question is why the null is printed when i concatenate the total variable which has a null value with the string "one".
    Is the null value converted to string ??
    Please clarify
    Regards and thanks!
    Carlos

    null is a keyword to inform compiler that the reference contain nothingNo. 'null' is not a keyword, it is a literal. Beyond that the compiler doesn't care. It has a runtime value as well.
    total contains null value means it does not have memory,No, it means it refers to nothing, as opposed to referring to an object.
    for representation purpose it contain "null"No. println(String) has special behaviour if the argument is null. This is documented and has already been described above. Your handwaving about 'for representation purpose' is meaningless. The compiler and the JVM don't know the purpose of the code.
    e.g. this keyword shows a hash value instead of memory addressNo it doesn't: it depends entirely on the actual class of the object referred to by 'this', and specifically what its toString() method does.
    similarly "total" maps null as a literal.Completely meaningless. "total" doesn't 'map' anything, it is just a literal. The behaviour you describe is a property of the string concatenation operator, not of string literals.
    I hope you can understand this.Nobody could understand it. It is compete nonsense. The correct answer has already been given. Please read the thread before you contribute.

  • 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.

  • Doubt on generic

    hi bw gurus,
    i am having one doubt in generic deltas.  if you are using calendar day for generic deltas suppose if i extracted data today and there are deltas posted after 3 pm. if i want to extract delta records after 3 pm.  is the calendar day option will work fine for that. or what is the scenario explain.
    explain about the safety intervals how it works will calendar day.
    what is BCS. can any one provide me the material for BCS.
    good links and good answers will be given points.

    Hi,
    Docs on BCS...
    http://help.sap.com/saphelp_nw04/helpdata/en/aa/29673a9011fc7be10000000a11402f/frameset.htm
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
    http://help.sap.com/saphelp_nw04/helpdata/en/a3/295c3c76054953e10000000a11405a/frameset.htm
    BCS
    SEM-BCS
    BW-BCS
    SEM-BCS WITH BW
    Hope this helps...
    Thanks,
    Raj

  • Doubt about Tunning View Objects

    Hi !. I have the following doubt about tunning View Objects:
    If I have the following configuration on a VO:
    All Rows
    In Batches Of: 11
    As Needed
    Access Mode: Scrollable
    Range Size: 10
    Total Records On The Table: More than 100
    What would happen is that while the initial render, the view cache is fetch with 11 rows from the table and the ui table shows 10. In subsequent scroll events, more queries again will be done but not when the user scrolls back. My doubt is this one: Why, while the initial render If I put a breakpoint in this overrided method executeQueryForCollection, the execution reachs there but in subsequent scroll events (forward) the execution doesn't reach there ?. I understand thast this should happen as the required rows are not yet in the cache. I would like to know a way to test this access mode and what method is executed in every roundtrip to the DB. Thankx !.

    I don't think ADF needs to execute the query again - it just needs to fetch the next set of records.
    So if the cursor is already open, no need to issue another query.
    You can use the HTTP Analyzer to watch network traffic
    Monitoring ADF Pages Round-Trips with the HTTP Analyzer
    And you can use the logging features of ADF to see the queries being executed.
    Declarative View Objects (VOs) for better ADF performance

  • 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.

Maybe you are looking for

  • Error while invoking a EBS

    Hi, I created an BPEL process process and tried to invoke an ESB process. ESB process is created using EBS. while i am trying to initiate the process with out any input in BPELconsole it is giving error that 'Could not initiate the BPEL process becau

  • Planning Sequence error - You do not have sufficient authorization

    Hello Experts, I am encountering the following error during execution of my planning sequence: You do not have sufficient authorization Message no. EYE007 Diagnosis You do not have sufficient authorization for the requested data records. Procedure Ei

  • Hp x20LED monitor

              Just bought an HP 17 envy computer with windows 8.1. When I plug my HP x20led into it using a  vga to HDMI adapter I get the image but there is a grey box floating around saying " Imput not supported "  or " signal not supported " , it's be

  • Paging and Non Destructive Filter

    Hi all, I am trying to create a list screen for a small application I am working on and I've hit a problem. Originally my list was to show just 10 results at a time and for this I used the code from the "Paging Sample" and managed to get this working

  • Need help with Data Model for Private Messaging

    Sad to say, but it looks like I just really screwed up the design of my Private Messaging (PM) module...  *sigh* What looked good on paper doesn't seem to be practical in application. I am hoping some of you Oracle gurus can help me come up with a be