Type parameter in 'add' method of 'ArrayList'

My little application utilizes an object of type 'ArrayList', especially because this class enables the size increment of the list by successive actions after its creation. http://java.sun.com/javase/6/docs/api/ shows that I can use the method '*add(E e)*' for this purpose.
The IDE I use is 'NetBeans IDE 6.5'.
My object of type 'ArrayList' is multi-dimensional and to build it up, I make use of a re-entering method. At the end of this last, one can thus see :
     chaîneCible.add(descendant);
     return (chaîneCible);In 'chaîneCible.add(...',
1) if I don't write the type E of the object e to append ('descendant')
- the pre-compiler doesn't grumble : It does not underline the statement in red
although the type of method parameter, own to 'descendant', is missing - e.g. 'String'.
- the debugger grumbles :
Note: C:\Documents and Settings\Me\My documents\ApplicPrograms\Application7\src\package\NoeudàCaseàCocher.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.2) if I add the type E of the object e to append - e.g. 'BigDecimal' - then
- the pre-compiler grumbles :
- It underlines the statement in red.
- "Missing ;" + "Cannot find symbol" + "Symbol : variable String" + "location : ..."
Confusion : It takes the type for an argument !
- although the API stipulates that it is mandatory to specify the type of the parameter in front of it.
3) I don't know when anymore, the compiler returned
Class 'ArrayList' - method 'add'
automatic casting of a 'String' into an 'Object' is refuted at compilationWhy cannot I specify the type E of the argument e, as the API requires ?
Thanks in advance.

Dear DrClap,
Here is an intermediate source code (121 lines) of my original code file (1145 lines) which is working well, except this arrayList.*add(E e)* issue.
You see here the declaration of the ArrayList, the code where I add entries to the ArrayList, the code where I try to "add the type E ...
By writing *add(E e)*, I am simply using the syntax mentioned in http://java.sun.com/javase/6/docs/api/
I guarantee that the code that I filtered out is not relevant to my arrayList.*add(E e)* issue.
It is going on a parser that inserts String data from an auxiliairy file at the time of parsing the principal source file (chaîneSource), to generate a target file (chaîneCible).
{code}
package arbreformtarif;
import java.util.ArrayList;
import java.math.BigDecimal;
class NoeudàCaseàCocher
String dénomFournis;
FormTarif donnéesàTéléch_CB;
Object[] formTarif;
private static Object[] formTarif_Libellés;
private static byte langue = 0;
private BigDecimal[] consommParticul;
NoeudàCaseàCocher (Object[] data_TariefForm,
String gewest,
String naam_Aanbod,
FormTarif dataToDownload_CB,
{ formTarif = data_TariefForm;
donnéesàTéléch_CB = dataTeDownloaden_CB;
private ArrayList assocLibellésAuxDonnées(Object[] chaîneSource)
{ byte nbreEléments = (byte) chaîneSource.length;
ArrayList chaîneCible = new ArrayList(nbreEléments);
Object descendant = null;
for (int nbreBoucle = 0; nbreBoucle < nbreEléments; nbreBoucle++)
{ Object élément = chaîneSource[nbreBoucle];
if (élément instanceof String)
{ switch (...) //
{ case 0:
switch (...)
{ case 1:
dénomFournis = (String) élément;
break;
case 2:
switch (...)
{ case 1:
moisDApplication = (String) élément;
break;
case 2:
break;
default:
break;
case 3:
break;
default:
break;
case 1:
switch (...)
{ case 0:
switch (...)
{ case 0:
break;
break;
default:
descendant = (String) élément;
} else
{ if (élément instanceof Boolean)
descendant = (Boolean) élément;
} else
{ if (élément instanceof BigDecimal)
descendant = (BigDecimal) élément;
} else
{ if (élément instanceof Object[])
switch (...)
{ case 0:
élément = ((Object[])formTarif[iCA[0][1]]);
break;
case 2:
switch (...)
{ case 0:
chaîneCible.add(((Object[])formTarif_Libellés[langue])[3]); // Always a String
break;
default:
break;
default:
break;
default:
descendant = (ArrayList)assocLibellésAuxDonnées((Object[]) élément);
} else
{ if (élément == null)
/* Note: C:\Documents and Settings\Charles\Mijn documenten\Applic Program\Java\CostComp_HomeElectric_2\
* src\arbreformtarifàtélécharger\Noeudà2CasesàCocher.java uses unchecked or unsafe operations.
* Note: Recompile with -Xlint:unchecked for details.
chaîneCible.add(descendant);
return (chaîneCible);
{code}
Remember that
- 'élément' and 'descendant' are, depending of the momentaneous case, of type String, BigDecimal, Boolean, Object[] or null.
- 'assocLibellésAuxDonnées' is a re-entering method.
Thanks

Similar Messages

  • Type parameter in ArrayList

    Hi all,
    I need to know the reason why the name of type parameter is not allowed to be the same as class name . For example,
    import java.util.Random;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class[b] bouncingBalls {
    static ArrayList<bouncingBalls> list = new ArrayList<bouncingBalls>();
         bouncingBalls a=new bouncingBalls();
         list.add(a);
         public static void main(String[] args) {
    Please help. Thanks.

    try this:
    public class bouncingBalls
        static ArrayList<bouncingBalls> list = new ArrayList<bouncingBalls>();
        static bouncingBalls a = new bouncingBalls(); // needs static here
        // list.add(a);  // this needs to be in a method
        public static void main(String[] args)
            list.add(a);
    }also, when posting code, please use code tags. Read up on them here.
    Message was edited by:
    petes1234

  • A question about a method with generic bounded type parameter

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

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

  • How to define a parameter in a method of type com.sap.tc.webdynpro.progmode

    Hi All,
    I want to define a parameter in a method, type of parameter is com.sap.tc.webdynpro.progmodel.api.IWDNode,
    But when I browse on type and tehn in local dictionary, I do not find this type of datatype, please suggest how to assign this data type to any method's parameter.
    Thanks in Advance.

    Hello Amit,
    Please include  webdynproprogmodel.jar to build path, which can be found at    /sap/eclipse/plugins/com.sap.tc.webdynpro.runtime/lib
    Then you could able to user datatype IWDNode in your code
    Let me know if you need the jar file 
    Regards,
    Madhu

  • Type for SENDER parameter in Class Method

    Hi all,
    I have an import parameter declared in a Class method .
    in SE38 program i want to retrieve through export parameter .
    But i am not able to figure how to defind the type of SENDER parameter . Please suggest if my perception is wrong or the point that i am missing here .
    Regards,
    Ry.

    Hi Vijay,
    Thank you for your reply . the problem i am having is the functionlaity of this report is it displays three grids and when ever i double click on a grid it should identify the particluar grid . i have highlighted in bold where i am encountering the problem. i am enclosing the class details and the report source code. Please suggest after going through it . thanks in advance.
    Class details that i have created :
    the class has a method handle_double_event with event handler double_click of CL_GUI_ALV_GRID . i have defined this in the method section.
    in public section section :
    public section.
      types GO_GRID1 type ref to CL_GUI_ALV_GRID .
      class-methods HANDLE_DOUBLE_CLICK
        for event DOUBLE_CLICK of CL_GUI_ALV_GRID
        importing
          ES_ROW_NO
          E_COLUMN
          E_ROW
          SENDER .
    in handle_double_event code :
    DATA:
      go_grid1         TYPE REF TO cl_gui_alv_grid,
      go_grid2         TYPE REF TO cl_gui_alv_grid,
      go_grid3         TYPE REF TO cl_gui_alv_grid.
    DATA:
      gt_knb1          TYPE STANDARD TABLE OF knb1,
      gt_vbak          TYPE STANDARD TABLE OF vbak,
      gt_vbap          TYPE STANDARD TABLE OF vbap.
      define local data
        DATA:
          ls_knb1      TYPE knb1,
          ls_vbak      TYPE vbak,
          ls_vbap      TYPE vbap.
       DATA: es_row_no type lvc_s_roid,
             e_column  type lvc_s_col,
             e_row     type lvc_s_row.
        *CASE sender. - here when i double click on the first grid go_grid1 it should go inside the go_grid1 . but it is not entering .*
          WHEN go_grid1.
            READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
            CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
            CALL METHOD go_grid1->set_current_cell_via_id
              EXPORTING
                 IS_ROW_ID    =
                 IS_COLUMN_ID =
                is_row_no    = es_row_no.
            Triggers PAI of the dynpro with the specified ok-code
            CALL METHOD cl_gui_cfw=>set_new_ok_code( 'ORDERS' ).
          WHEN go_grid2.
            READ TABLE gt_vbak INTO ls_vbak INDEX e_row-index.
            CHECK ( ls_vbak-vbeln IS NOT INITIAL ).
            CALL METHOD go_grid1->set_current_cell_via_id
              EXPORTING
                 IS_ROW_ID    =
                 IS_COLUMN_ID =
                is_row_no    = es_row_no.
            Triggers PAI of the dynpro with the specified ok-code
            CALL METHOD cl_gui_cfw=>set_new_ok_code( 'ORDER_DET' ).
          WHEN go_grid3.
            READ TABLE gt_vbap INTO ls_vbap INDEX e_row-index.
            CHECK ( ls_vbap-matnr IS NOT INITIAL ).
            SET PARAMETER ID 'MAT' FIELD ls_vbap-matnr.
            CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
          WHEN OTHERS.
            RETURN.
        ENDCASE.
    endmethod.
    Code for the Report that is accessing the class.
    DATA:
      gd_okcode        TYPE ui_func,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_splitter      TYPE REF TO cl_gui_splitter_container,
      go_splitter_2    TYPE REF TO cl_gui_splitter_container,
      go_cell_top      TYPE REF TO cl_gui_container,
      go_cell_bottom   TYPE REF TO cl_gui_container,
      go_cell_left     TYPE REF TO cl_gui_container,
      go_cell_right    TYPE REF TO cl_gui_container,
      go_grid1         TYPE REF TO cl_gui_alv_grid,
      go_grid2         TYPE REF TO cl_gui_alv_grid,
      go_grid3         TYPE REF TO cl_gui_alv_grid,
      list             type ref to zcl_eventhandler,
      es_row_no        type lvc_s_roid,
      e_column         type lvc_s_col,
      e_row            type lvc_s_row,
      sender(8)        type c.
    DATA:
      gt_knb1          TYPE STANDARD TABLE OF knb1,
      gt_vbak          TYPE STANDARD TABLE OF vbak,
      gt_vbap          TYPE STANDARD TABLE OF vbap.
    PARAMETERS  :  p_bukrs TYPE ekko-bukrs default '1000'.
    START-OF-SELECTION.
      create object list.
      SELECT        * FROM  knb1 INTO TABLE gt_knb1
             WHERE  bukrs  = p_bukrs.
    Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent                      = cl_gui_container=>screen0
          ratio                       = 50
        EXCEPTIONS
          OTHERS                      = 6.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Create splitter container
      CREATE OBJECT go_splitter
        EXPORTING
          parent            = go_docking
          rows              = 1
          columns           = 1
         NO_AUTODEF_PROGID_DYNNR =
         NAME              =
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Get cell container
      CALL METHOD go_splitter->get_container
        EXPORTING
          row       = 1
          column    = 1
        RECEIVING
         container = go_cell_left.
          container = go_cell_top.
      CALL METHOD go_splitter->get_container
        EXPORTING
          row       = 1
          column    = 2
        RECEIVING
          container = go_cell_right.
    Create 2nd splitter container
      CREATE OBJECT go_splitter_2
        EXPORTING
         parent            = go_cell_left
          parent            = go_cell_top
          rows              = 2
          columns           = 1
         NO_AUTODEF_PROGID_DYNNR =
         NAME              =
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Get cell container
      CALL METHOD go_splitter_2->get_container
        EXPORTING
          row       = 1
          column    = 1
        RECEIVING
          container = go_cell_top.
      CALL METHOD go_splitter_2->get_container
        EXPORTING
          row       = 2
          column    = 1
        RECEIVING
          container = go_cell_bottom.
    Create ALV grids
      CREATE OBJECT go_grid1
        EXPORTING
          i_parent          = go_cell_top
        EXCEPTIONS
          OTHERS            = 5.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CREATE OBJECT go_grid2
        EXPORTING
          i_parent          = go_cell_bottom
        EXCEPTIONS
          OTHERS            = 5.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CREATE OBJECT go_grid3
        EXPORTING
          i_parent          = go_cell_right
        EXCEPTIONS
          OTHERS            = 5.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
          CALL METHOD ZCL_EVENTHANDLER=>HANDLE_DOUBLE_CLICK
            EXPORTING
              ES_ROW_NO = ES_ROW_NO
              E_COLUMN  = E_COLUMN
              E_ROW     = E_ROW
              SENDER.
    Set event handler
      SET HANDLER: list->handle_double_click FOR go_grid1.
      SET HANDLER: list->handle_double_click FOR go_grid2.
      SET HANDLER: list->handle_double_click FOR go_grid3.
    Display data
      CALL METHOD go_grid1->set_table_for_first_display
        EXPORTING
          i_structure_name = 'KNB1'
        CHANGING
          it_outtab        = gt_knb1
        EXCEPTIONS
          OTHERS           = 4.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      REFRESH: gt_vbak.
      CALL METHOD go_grid2->set_table_for_first_display
        EXPORTING
          i_structure_name = 'VBAK'
        CHANGING
          it_outtab        = gt_vbak
        EXCEPTIONS
          OTHERS           = 4.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      REFRESH: gt_vbap.
      CALL METHOD go_grid3->set_table_for_first_display
        EXPORTING
          i_structure_name = 'VBAP'
        CHANGING
          it_outtab        = gt_vbap
        EXCEPTIONS
          OTHERS           = 4.
      IF sy-subrc <> 0.
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Link the docking container to the target dynpro
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = syst-repid
          dynnr                       = '0100'
         CONTAINER                   =
        EXCEPTIONS
          OTHERS                      = 4.
      IF sy-subrc <> 0.
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    NOTE: dynpro does not contain any elements
      CALL SCREEN '0100'.
    Flow logic of dynpro:
    *PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    *PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0100.
    END-OF-SELECTION.
    *&      Form  CUSTOMER_SHOW_ORDERS
          text
    -->  p1        text
    <--  p2        text
    FORM customer_show_orders .
    define local data
      DATA:
        ld_row      TYPE i,
        ls_knb1     TYPE knb1.
      CALL METHOD go_grid1->get_current_cell
        IMPORTING
          e_row = ld_row.
      READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
      CHECK ( syst-subrc = 0 ).
      SELECT        * FROM  vbak INTO TABLE gt_vbak
             WHERE  kunnr  = ls_knb1-kunnr.
      REFRESH: gt_vbap.
    ENDFORM.                    " CUSTOMER_SHOW_ORDERS
    *&      Form  ORDER_SHOW_DETAILS
          text
    -->  p1        text
    <--  p2        text
    FORM order_show_details .
    define local data
      DATA:
        ld_row      TYPE i,
        ls_vbak     TYPE vbak.
      CALL METHOD go_grid1->get_current_cell
        IMPORTING
          e_row = ld_row.
      READ TABLE gt_vbak INTO ls_vbak INDEX ld_row.
      CHECK ( syst-subrc = 0 ).
      SELECT        * FROM  vbap INTO TABLE gt_vbap
             WHERE  vbeln  = ls_vbak-vbeln.
    ENDFORM.                    " ORDER_SHOW_DETAILS
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'STATUS_0100'.  " contains push button "ORDERS"
    SET TITLEBAR 'xxx'.
    Refresh display of detail ALV list
      CALL METHOD go_grid2->refresh_table_display
       EXPORTING
         IS_STABLE      =
         I_SOFT_REFRESH =
        EXCEPTIONS
          OTHERS         = 2.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Refresh display of detail ALV list
      CALL METHOD go_grid3->refresh_table_display
       EXPORTING
         IS_STABLE      =
         I_SOFT_REFRESH =
        EXCEPTIONS
          OTHERS         = 2.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE USER_COMMAND_0100 INPUT.
    move sy-ucomm to gd_okcode.
    CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
      User has pushed button "Display Orders"
        WHEN 'ORDERS'.
          PERFORM customer_show_orders.
        WHEN 'ORDERS_DET'.
          PERFORM order_show_details.
        WHEN OTHERS.
      ENDCASE.
      CLEAR: gd_okcode.
    endmodule.
    Regards,
    Ry

  • Type parameter instances.

    Hi, thanks for reading.
    I'm trying to implement a parametrized class which has an (obviously) parametrized array.
    The code:
    public class PQ<T> {
        protected T[] pq;
        protected Comparator<T> comparator;
        protected int N;That's OK but I can't create instances of pq.
    The error "Type parameter 'T' cannot be instantatied directly".
    What can I do? I need to work with that array instance to add, remove items, etc!
    Edited by: Akcents on Sep 29, 2008 7:04 PM

    Ugly? Yeah, arrays and generics don't go very nicely together. Here's my take at it (removed confusing N arg from constructor):
    public class AbstractPQ<T> {
        private Comparator<T> comparator;
        protected T[] pq;
        protected int N;
        protected AbstractPQ(Comparator<T> comparator) {
            pq = (T[]) new Object[0];
            this.comparator = comparator;
        }getMax now doesn't need casts anymore.
    If you don't like the warning generated for the unchecked cast to T[] in the constructor, refactor array creation into a method (or variable declaration) and use a SuppressWarnings-annotation:
    public class AbstractPQ<T> {
        private Comparator<T> comparator;
        protected T[] pq;
        protected int N;
        protected AbstractPQ(Comparator<T> comparator) {
            pq = createArray(0);
            this.comparator = comparator;
        @SuppressWarnings("unchecked")
        private T[] createArray(int length) {
           return (T[]) new Object[length];
        }Edited by: nygaard on Sep 29, 2008 10:05 PM

  • I am trying to export the combained PDF based on BOOK opetion using below scripts. but i am getting following error message "Invalid value for parameter 'to' of method 'exportFile'. Expected File, but received 1952403524". anyone knows, please suggest me

    Dear ALL,
    i am trying to export the combained PDF based on BOOK opetion using below scripts. but i am getting following error message "Invalid value for parameter 'to' of method 'exportFile'. Expected File, but received 1952403524". anyone knows, please suggest me solutions.
    var myBookFileName ,myBookFileName_temp;
                    if ( myFolder != null )
                            var myFiles = [];
                            var myAllFilesList = myFolder.getFiles("*.indd");    
                            for (var f = 0; f < myAllFilesList.length; f++)
                                        var myFile = myAllFilesList[f]; 
                                        myFiles.push(myFile);
                            if ( myFiles.length > 0 )
                                        myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
                                        myBookFileName_temp=myFolder.name ;
                                        myBookFile = new File( myBookFileName );
                                        myBook = app.books.add( myBookFile );  
                                       myBook.automaticPagination = false;
                                        for ( i=0; i < myFiles.length; i++ )
                                                   myBook.bookContents.add( myFiles[i] );             
                                        var pdfFile =File(File(myFolder).fsName + "\\"+myBookFileName_temp+"_WEB.pdf");
                                        var bookComps = myBook.bookContents;
                                        if (bookComps.length === 1)
                                                       bookComps = [bookComps];
                                         var myPDFExportPreset = app.pdfExportPresets.item("AER6");
                                        app.activeBook.exportFile(ExportFormat.PDF_TYPE,File("D:\\AER\\WEBPDF.pdf"),false,myPDFEx portPreset,bookComps);
                                      //myBook.exportFile (ExportFormat.pdfType, pdfFile, false);
                                      //myBook.exportFile(pdfFile, false, pdfPref, bookComps);
                                        myBook.close(SaveOptions.yes);      

    Change the below line:
    app.activeBook.exportFile(ExportFormat.PDF_TYPE,File("D:\\AER\\WEBPDF.pdf"),false,myPDFExp ortPreset,bookComps);
    to
    app.activeBook.exportFile(ExportFormat.PDF_TYPE,File("D:\\AER\\WEBPDF.pdf"),false,myPDFExp ortPreset);
    Vandy

  • Problem with remove() method of ArrayList collection

    Dear All,
    I have a program below: See the statement in bold
    //Start of the Program
    import java.util.*;
    public class ArrayListTest
         public static void main(String args[])
              //declare an arraylist of type String
              List<String> stringStorage = new ArrayList<String>();
              //add elements to the ArrayList
              stringStorage.add("apple");
              stringStorage.add("banana");
              stringStorage.add("papaya");
              stringStorage.add("peach");
              stringStorage.add("cucumber");
              stringStorage.add("orange");
              stringStorage.add("grapes");
              stringStorage.add("plum");
              stringStorage.add("chiku");
              stringStorage.add("pomegrenate");
              stringStorage.add("pomegrenate2");
              //iterate through the ArrayList
              Iterator<String> iterate = stringStorage.iterator();
              //test whether an element is present
              boolean isPresent = stringStorage.contains("xxx");
              System.out.println("xxx is Present "+isPresent);
              //remove an element from the ArrayList
    Line no: 12     System.out.println("Remove apple:(true/false)"+stringStorage.remove("apple"));
              Loop:
              for (int i=0;i<stringStorage.size();i++)
                   while (iterate.hasNext()==true)
                        System.out.println("Element in the arraylist["+i+"] "+iterate.next());
                        //iterate.remove();
                        continue Loop;
    End of Outer Loop:
    //End of the Program
    It compiles fine. But when I try to run , it gives a unchecked exception in main ConcurrentModificationException.
    Exception in thread "main" java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
    at java.util.AbstractList$Itr.next(Unknown Source)
    at ArrayListTest.main(ArrayListTest.java:48)
    But, if I remove Line no 12(in bold), or put the same statement after End of Outer Loop: , I do not get the error. Can you explain this phenomenon?

    look what you do:
    1/ you retrieve the iterator
    2/ you remove apple
    3/ you browse the iterator
    but actually, the iterator kept a reference to the "apple" you just removed ; that s why it gets screwed ;
    you mustn't operate on the list if you re not over with the iterator work

  • Field symbol as import parameter in class method ???

    Hi everyone,
    is it possible to pass a field symbol as an import parameter to a method in a class? If yes, how do I define the data type of the import parameter? I'm trying to work with field symbols as the program doesn't know what kind of structure the program parameter p_srcdso has. Coding example would be something like this:
    PARAMETERS: p_srcdso TYPE rsdodsobject DEFAULT '/BIC/AKVI0001'.
    DATA: lr_srcpkg TYPE REF TO data.
    FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE.
    CREATE DATA lr_srcpkg TYPE TABLE OF (p_srcdso).
    ASSIGN lr_srcpkg->* TO <fs_table>.
    SELECT *
    FROM (p_srcdso)
    INTO TABLE <fs_table>.
    CALL METHOD cl_ref->create_somethign
    EXPORTING
        i_source_package = <fs_table>.
    Thanks,
    Alex

    Halo Alexander,
    You can use TYPE REF TO DATA( say the parameter name is i_data) as the importing parameter of the method create_somethign and inside the method you need to dereference it using data reference variable again.
    data: dref type ref to data.
    field-symbols: <fs_table> type table.
    create data dref like i_data.
    assign dref->* to <fs_table>.
    Regards
    Arshad

  • JLS3: Scope of type parameter and inner class declaration

    The following code:
    class Foo<E>
      class E
        E foo()
          return this;
    }produces this error message:
    $ javac Foo.java
    Foo.java:7: incompatible types
    found   : Foo<E>.E
    required: E
          return this;
                 ^
    1 errorApparently, the type parameter E of the outer class Foo shadows the inner class declaration E. An alternative way to check is to create a new E() in this method, which results in an error message about using a type parameter where a type is expected.
    Of course this code is sick, but I would like to know where this is defined in the JLS3, since I cannot find out in which way this shadowing works. What I've found until now:
    Page 179:
    "The scope of a class' type parameter is the entire declaration of the class."
    Page 190:
    "The scope of a declaration of a member m declared in or inherited by a class type C is the entire body of C, ... "
    Page 132:
    "If a type name consists of a single Identifier, then the identifier must occur in the scope of exactly one visible declaration of type with this name, or a compile time error occurs."
    Section 6.3.1 (Shadowing declarations) specifies the shadowing rules, but does not mention type parameters.
    Any help is appreciated.

    The current behaviour in eclilpse seems to be the one we get if the bug in javac is fixed as described.
    This code compiles
    public class Shadow1 {
         class Foo<E>
           class E
              E foo()
               return this;
    }but this code
            Foo<E>.E foo()
               return this;
             }shows
    Type mismatch: cannot convert from Shadow1.Foo<E>.E to Shadow1.Foo<Shadow1.Foo<E>.E>. E
    Not sure if this error message is correct.

  • Passing a Vector object as a parameter to a method

    Hi,
    How can I pass a Vector object as a parameter to a method?
      void buttonAdd_actionPerformed(ActionEvent e) {
        Vector studentHobbies = new Vector();
          String[] items = listHobbies.getSelectedItems();
          for (int i=0; i<items.length; i++) {
            studentHobbies.addElement(items);
    newStudent = new Student(Name,StudentNumber,studentHobbies);
    studentenlist.addTo(newStudent);
    So I want to pass the Vector object 'studentHobbies'  to a method.
    Would I do something like this :import java.util.Vector;
    public Student(String Name, int StudentenNumber, Vector studentHobbies){
    this.Name = Name;
    this.StudentNumber = StudentNumber;
    this.studentHobbies = StudentenHobbies;

    yes, thats how you do it.
    maybe you should first try your idea and then ask people questions?
    also, use ArrayList instead of Vector, its better - google as to why if you care.

  • How to pass field symbol as parameter to a method

    Hi,
    I have a field symbol of type table,also i have a method with parameter (say vbeln), i need to pass the range value in <fs> as the parametrs to the method.,
    How can I acheive this,
    A code snippet eill help me a lot.,
    Thank you.
    Arjun.G

    Hi,
    Example code :
    field-symbols : <fs> type table.
    CALL METHOD cl_gui_frontend_services=>gui_upload
      CHANGING
        data_tab                = <fs>
    *  EXCEPTIONS
    *    file_open_error         = 1
    *    file_read_error         = 2
    *    no_batch                = 3
    *    gui_refuse_filetransfer = 4
    *    invalid_type            = 5
    *    no_authority            = 6
    *    unknown_error           = 7
    *    bad_data_format         = 8
    *    header_not_allowed      = 9
    *    separator_not_allowed   = 10
    *    header_too_long         = 11
    *    unknown_dp_error        = 12
    *    access_denied           = 13
    *    dp_out_of_memory        = 14
    *    disk_full               = 15
    *    dp_timeout              = 16
    *    not_supported_by_gui    = 17
    *    error_no_gui            = 18
    *    others                  = 19
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Remember : parameter should be of type standard table.
    Regards,
    Mohaiyuddin

  • [JS CS3] What does copyingProfiles parameter of packageForPrint method mean?

    Hi all,
    I wrote a script that packages all InDesign files in the selected folder — the script and its detailed description is here: http://kasyan.ho.com.ua/package_for_archive.html
    But I can’t figure out what copyingProfiles parameter of packageForPrint method means?
    First of all, I don’t see the corresponding checkbox in InDesign’s Package Publication dialog box.
    Secondly, it makes no difference whether I set it to true or false: no profiles are copied.
    The reference states: “copyingProfiles — bool — If true, copies color profiles to the package folder”.
    But what profiles is it supposed to copy? The ones chosen in Color Settings dialog?
    Kasyan

    [Still OT ...] Weird.
    7-Zip reports the compression of Windows' "Send to compressed folder" zips as "Deflate" -- I would say that's pretty old fashioned. Your file gets a description of "LZMA", which doesn't really tell me anything at all. Perhaps it's too old.[*]
    [Really getting OT for InDesign Scripting] 7-Zip for Windows is free (http://www.7-zip.org/), fast, user friendly, can compress and unpack from the Explorer, and supports lots and lots of file types. Even a Mac archived .DMG file is not a problem! (You do need to know the basics of that, though.) Weirdest-I-found-so-far: you can "open" a Windows Executable program and extract its code and data segments ...
    [Ed.] [*] Idly browsing the 7-zip site, I came across a description of its native compression:
    "LZMA is default and general compression method of 7z format. The main features of LZMA method:"
    (a list of super-modern features follows -- including multi- and P4-hyper-threading.)
    That's what WinZip calls "legacy"? Boy am I getting old.

  • How to Pass Select-options Single values as Parameter value to Method ?

    Hi Friends,
    I need to pass select-options values(single values) for s_arbpl to the method "process_percent_planned". Now all single values are in internal table s_arbpl-low field. I need to pass this internal table(s_arbpl-low) values to the method where i will run query based on these single values.In my below code i am passing value through variable w_arbpl. I have defined this parameter in the method.But here only one value is passed to method. I want multiple single values (in s_arbpl-low) should be passed. Please let me know how to correct code.
    Tables: crhd.
    Data: ktext type auftext,
    w_arbpl type arbpl.
    select-options: s_arbpl for crhd-arbpl.
    ktext = 'Test'
    create object obj_plan.
    call method obj_plan->process_percent_planned
    exporting
    ktext = ktext
    w_arbpl = s_arbpl-low.
    Thanks

    hi ,
    when you want to pass  S_ARBPL AS PARAMETER IN SELEC OPTION
    ARBPL SUCH AS  
       WIN002
      WIN003
      WIN004
      WIN005
      WIN006
      WIN007
    IN MULTIPLE SELECTION  S_ARBPL
    THEN
    USE  
    Tables: crhd.
    Data: ktext type auftext,
    w_arbpl type arbpl.
    select-options: s_arbpl for crhd-arbpl.
    ktext = 'Test'
    LOOP AT S_ARBPL .
    create object obj_plan.
    call method obj_plan->process_percent_planned
    exporting
    ktext = ktext
    w_arbpl = s_arbpl-low.
    ENDLOOP.
    REGARDS
    dEEPAK .
       THEN SELECT THAT
    call method obj_plan->process_percent_planned
    exporting
    ktext = ktext
    w_arbpl = s_arbpl-low.

  • Passing an Internal Table as parameter to a method

    Hi,
       Can we pass an internal table as a parameter to a method.if so how can we do that?i am new to abap objects..

    Hi Matt,
            Here is the code that i am trying to execute.I am extracting the data in the method "Extract" and passing it to the method "Display" to produce a report output.When i execute this it is giving me an error saying that t_mara is not an internal table since i just refered it with x_mara in the class definition.So how can i modify this code to pass t_mara as an internal table from the method "Extract".Please help me.
    *& Report  ZOBJ_PRAC                                      *
    REPORT  zobj_prac                                                   .
          CLASS example DEFINITION
    CLASS example DEFINITION.
      PUBLIC SECTION.
            TYPES : BEGIN OF x_mara,
                  matnr TYPE matnr,
                  ersda TYPE ersda,
               END OF x_mara.
        METHODS : extract EXPORTING t_mara TYPE x_mara,
                          display IMPORTING it_mara TYPE x_mara.
    ENDCLASS.                    "example DEFINITION
    "example IMPLEMENTATION
          CLASS example IMPLEMENTATION
    CLASS example IMPLEMENTATION.
      METHOD extract.
        DATA :lt_mara TYPE STANDARD TABLE OF x_mara INITIAL SIZE 0,
                  lw_mara TYPE x_mara.
        SELECT matnr ersda FROM mara INTO TABLE lt_mara UP TO 10 ROWS.
        t_mara[]  =  lt_mara[].
      ENDMETHOD.                    "extract
      METHOD display.
        DATA :lt_mara TYPE STANDARD TABLE OF x_mara INITIAL SIZE 0,
              lw_mara TYPE x_mara.
        lt_mara[]  =  it_mara[].
        LOOP AT lt_mara INTO lw_mara.
          WRITE:/ lw_mara-matnr,
                20 lw_mara-ersda.
        ENDLOOP.
      ENDCLASS.                    "example IMPLEMENTATION
    START-OF-SELECTION.
      DATA :  b1 TYPE REF TO example.
    CREATE OBJECT b1 TYPE example.
      TYPES : BEGIN OF x_mara,
                  matnr TYPE matnr,
                  ersda TYPE ersda,
               END OF x_mara.
    data : t_mara type standard table of x_mara initial size 0,
           it_mara type standard table of  x_mara initial size 0.
      call method b1->extract
        importing
         t_mara = t_mara.
         it_mara[]  =  t_mara[].
      call method b1->display
        exporting
         it_mara = it_mara.
    Edited by: Sai Chaitanya on Dec 2, 2008 5:30 AM

Maybe you are looking for

  • Probably a stupid display question

    I shoot with a canon xh-a1 edit with a mbp 15". What im wondering is if I wanted to edit on a bigger screen then my laptop and do some coloring, would it be stupid to think that using a lcd tv as a display would work? The reason I ask is I could go t

  • How to loop through a Data Node

    Hello, I have an Interactive Adobe form in WebDynpro Java project.  My data View tab includes the following structure: Bapi_test ValueHelpData CodeNumber CodeDescription Can someone please tell how I can loop through the “ValueHelpData” node, and get

  • Inventory management configuration for Rollout project.

    Hi all, We have created new plant using Copy function (using reference Plant). Kindly let me know what are other configuration required for Inventory management in new plant? Please provide if any check list available for Roll-out project. Thanks SAP

  • Portlet Registration Error

    Hi to all, I am facing problem while trying to registering a portlet producer. The Error is given below. I am following Oracle Webcenter 11g PS3 Administration Cookbook. Kindly give the solution. oracle.portlet.client.container.PortletRemoteException

  • HT204088 i didn't receive this application

    i didn't receive this application