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

Similar Messages

  • Taglib parsing error - cant see type parameter under attribute apparent

    Hi,
    I cannot determine why I'm getting the following error:
    "org.apache.jasper.JasperException: XML parsing error on file /report-taglib.tld: Element type "type" must be declared."
    It seems to me that I have clearly included the "<type>"
    parameter (java.util.ArrayList) for the "container" attribute (see my taglib xml, below)...
    Can you tell why the parser does not recognize it?
    Appreciate any help.
    [environment info]
    OS: WIN2000
    JAVA_HOME: C:\j2sdk1.4.0
    J2EE_HOME: C:\j2sdkee.1.3.1
    CATALINA_HOME: C:\jwsdp-1_0-ea1
    [my taglib]
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <!-- a tag library descriptor -->
    <taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>report-taglib</shortname>
    <info>
              report taglib
    </info>
    <tag>
    <name>report</name>
    <tagclass>reportpackage.reporttags.ReportTagPROTO</tagclass>
    <bodycontent>JSP</bodycontent>
    <info>Includes body only if authorized by tag servlet</info>
    <attribute>
         <name> numQuery </name>
         <required> true </required>
         <rtexprvalue> true </rtexprvalue>
    </attribute>
    <attribute>
         <name> showNumber </name>
         <required> true </required>
         <rtexprvalue> true </rtexprvalue>
    </attribute>
    <attribute>
         <name> container </name>
         <required> true </required>
         <rtexprvalue> true </rtexprvalue>
         <type> java.util.ArrayList </type>
    </attribute>
    </tag>
    </taglib>

    It appears that this error is a result of using the wrong jsp version. -thanks

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

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

  • Java call stored procedure with nested table type parameter?

    Hi experts!
    I need to call stored procedure that contains nested table type parameter, but I don't know how to handle it.
    The following is my pl/sql code:
    create or replace package test_package as
    type row_abc is record(
    col1 varchar2(16),
    col2 varchar2(16),
    col3 varchar2(16 )
    type matrix_abc is table of row_abc index by binary_integer;
    PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
    p_arg2 IN VARCHAR2,
    p_arg3 IN VARCHAR2,
    p_out OUT matrix_abc
    END test_package;
    create or replace package body test_package as
    PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
    p_arg2 IN VARCHAR2,
    p_arg3 IN VARCHAR2,
    p_out OUT matrix_abc
    IS
    v_sn NUMBER(8):=0 ;
    BEGIN
    LOOP
    EXIT WHEN v_sn>5 ;
    v_sn := v_sn + 1;
    p_out(v_sn).col1 := 'col1_'||to_char(v_sn)|| p_arg1 ;
    p_out(v_sn).col2 := 'col2_'||to_char(v_sn)||p_arg2 ;
    p_out(v_sn).col3 := 'col3_'||to_char(v_sn)||p_arg3 ;
    END LOOP ;
    END ;
    END test_package ;
    My java code is following, it doesn't work:
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection
    ("jdbc:oracle:thin:@10.16.102.176:1540:dev", "scott", "tiger");
    con.setAutoCommit(false);
    CallableStatement ps = null;
    String sql = " begin test_package.test_matrix( ?, ? , ? , ? ); end ; ";
    ps = con.prepareCall(sql);
    ps.setString(1,"p1");
    ps.setString(2,"p2");
    ps.setString(3,"p3");
    ps.registerOutParameter(4,OracleTypes.CURSOR);
    ps.execute();
    ResultSet rset = (ResultSet) ps.getObject(1);
    error message :
    PLS-00306: wrong number or types of arguments in call to 'TEST_MATRIX'
    ORA-06550: line 1, column 8:
    PL/SQL: Statement ignored
    Regards
    Louis

    Louis,
    If I'm not mistaken, record types are not allowed. However, you can use object types instead. However, they must be database types. In other words, something like:
    create or replace type ROW_ABC as object (
    col1 varchar2(16),
    col2 varchar2(16),
    col3 varchar2(16 )
    create or replace type MATRIX_ABC as table of ROW_ABC
    /Then you can use the "ARRAY" and "STRUCT" (SQL) types in your java code. If I remember correctly, I recently answered a similar question either in this forum, or at JavaRanch -- but I'm too lazy to look for it now. Do a search for the terms "ARRAY" and "STRUCT".
    For your information, there are also code samples of how to do this on the OTN Web site.
    Good Luck,
    Avi.

  • Complicated PL/SQL questions that involves function with in type parameter

    Hello,
    I have a question about functions with in-parameters. In the HR schema, I need to get the minimum salary of the job_id that is mentioned as an in-parameter.
    this is what I am thinking but I dont know if it's correct or not or what should I do next!
    create or replace function get_min_salary (i_job_id in varchar2)
    return number
    as
    min_sal jobs.min_salary%type;
    begin
    SELECT min_salary INTO min_sal
    FROM jobs
    where job_id = i_job_id;
    RETURN min_sal;
    end get_min_salary;if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:
    create or replace procedure insert_error (i_error_code in number,
    i_error_message in varchar2)
    as
    begin
    insert into error_table (error_user, error_date, error_code, error_message)
    values (user,sysdate,i_error_code,i_error_message);
    end insert_error;This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
    Any ideas of how to do that?
    Thanks in advance

    >
    minimum salary of the job_id
    >
    may be
    SELECT min(min_salary) INTO min_sal
    FROM jobs
    where job_id = i_job_id;
    if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:why error?
    This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
    create or replace procedure insert_error (i_error_code in number,
    i_error_message in varchar2)
    as
    begin
    insert into error_table (error_user, error_date, error_code, error_message)
    values (user,sysdate,i_error_code,i_error_message);
    -- this
    dbms_out.put_line('this');
    end insert_error;

  • Optional Prompt for Date type parameter in Crystal Report.

    Hi Every One,
    I have a date type parameter in crystal report.When I am convert it to optional prompt it is showing following message.
    But the Type field is gray out when I was selecting list of values Dynamic.
    Please suggest.
    Thanks and Regards
    DEV

    Hi,
    Please check SAP note:
    1710595 - CR_Defining "Optional Prompt" as True for SAP Crystal
    Reports Does Not Work
    Thanks & Regards,
    Nagarajan

  • How to pass attribute of type java.util.ArrayList Property to a Tag

    How do I pass an attribute of type, java.util.ArrayList<my.entity.Property> to a Tag implementation class?
    Please advise!
    Thanks,
    Joe
    package my.tags;
    import java.io.IOException;
    import java.util.ArrayList;
    import javax.servlet.jsp.tagext.SimpleTagSupport;
    import javax.servlet.jsp.JspException;
    import my.entity.Property;
    public class PropertiesTag extends SimpleTagSupport {
        private ArrayList<Property> properties;
        public void setProperties(ArrayList<Property> properties) {
              this.properties = properties;
         public void doTag() throws JspException, IOException {
    <?xml version="1.0" encoding="utf-8" ?>
    <taglib ...>
         <tag>
              <name>propertiesTag</name>
              <tag-class>my.tags.PropertiesTag</tag-class>
              <body-content>empty</body-content>
              <description>Displays the product selection left menu</description>
              <attribute>
                   <name>properties</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
                   <type>java.util.ArrayList<my.entity.Property></type>
              </attribute>
         </tag>
    </taglib>Here's the error message:
    org.xml.sax.SAXParseException: The element type "my.entity.Property" must be terminated by the matching end-tag "</my.entity.Property>".

    802826 wrote:
    How do I pass an attribute of type, java.util.ArrayList<my.entity.Property> to a Tag implementation class?
    Please advise!
    As already pointed out, there is no way to specify a generic type in a tag library descriptor. You may however specify an Object type in your tld and still have the variable in your tag as a parameterized generic type.
    In your tld change the type to Object.
    <type>java.lang.Object</type>.
    The properties tag itself needs no change and can continue to use parameterized types.
    cheers,
    ram.

  • How to specify Complex Type Parameter

    Hi,
    Can anyone tell me how to specify a complex type parameter using the AddServiceDefinition command in the fnscript? Thanks
    Pao Wang
    NMR

    The only types supported are those listed in the Process Development Guide.
    Stephen

  • Clear definition+examples- type variable, type parameter and type argument

    I am trying to fully understand the terms like type variable, type parameter and type argument as they apply to generics. Can anyone please give the exact definition and example of each of these terms. Also how these terms relate to the classes/interfaces in language model APIs of Java 6.

    http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

  • Using a type parameter at the 'wrong' time?

    I tried to make a subclass of SwingWorker using...
    private class ProcessSAV<Void, String> extends SwingWorker {...}...and in the doInBackground() method, I declared and initialized a local variable...
    String filename = "blahblahblah";Somehow, I manage to get an incompatible types compile-time error at this line of code.
    found: java.lang.String
    required: String
    I know that the second type parameter is used to the specify the object type in publish() as well as the List type in process(). When I declare a String as the local variable in this instance, it seems to be a unique type related the second type argument and won't accept anything that returns a java.lang.String.
    Why is it doing this? And is there any way to get around it?

    You created two type parameters having the names of classes, thus the String you refer to actually is a type parameter, not the String class.
    You most probably wanted to do the following:private class ProcessSAV extends SwingWorker<Void, String> {...}

  • Type parameter question

    I'm trying to figure out if I can simplify this interface definition:
    public interface BaseService<T extends BaseEntity<ID>, ID> {
        public T find(ID id);
        public void persist(T entity);
    }To implement this interface, I have to do something like:
    public class CountryService implements BaseService<Country, Long> {}Where Country is defined like:
    public class Country extends BaseEntity<Long> {}My question is: Is there some way to get rid of the second type parameter in BaseService, so that I can do this instead:
    public class CountryService implements BaseService<Country> {}but still enforce the type of the id parameter on the find() method in BaseService?
    The obvious solution doesn't compile:
    {color:#ff0000}public interface BaseService<T extends BaseEntity<ID>> {
       public T find(ID id);
       public void persist(T entity);
    }{color}
    Any help is greatly appreciated!

    Hi,
    Another suggestion is to parametrize BaseEntity on a ID hierarchy
    public abstract class BaseEntity<T extends ID> {
        public abstract T getId();
    }This can lead to the following the BaseService:
    public interface BaseService<T extends BaseEntity<? extends ID>> {
        T find(ID id);
        void persist(T entity);
    }Now if you define Country as
    public class Country extends BaseEntity<ID> {
        @Override
        public ID getId() {
            return null;
    }and finally CountryService as
    public class CountryService implements BaseService<Country> {
        @Override
        public Country find(ID id) {
            return null;
        @Override
        public void persist(Country entity) {
    }Hope this help.

  • Receiver ABAPProxy-Addressing Type parameter

    Hi,
    In receiver ABAPProxy, we have Addressing Type parameter, which has two options 1. URL Address and 2. HTTP destination.
    What is difference between two and when to choose?
    Thanks,
    Pragathi.

    we have 1. SDN and 2. help.sap.com
    What is difference between two and when to choose?
    http://help.sap.com/saphelp_nwpi71/helpdata/EN/85/78af1bf407434796aaf8dbd6d4e7b7/frameset.htm

  • HTTPS Receiver Adapter POST with FILE TYPE parameter

    Hello,
    I need to do a POST to a URL service that validates content of a file. It receives user and password as string parameters and a FILE as a mime type parameter.
    I'll appreciate any help.
    Regards,
    Diego.

    Hi.
    Using Http Receiver Adapter , you can try out this.
    This blog may give some idea-
    /people/amol.joshi2/blog/2006/06/28/must-fire-a-http-get-from-xi---try-this
    Otherwise, try out with callinng this service via SOAP Adapter i.e webservice.
    Rgds,
    moorthy

  • Switch datetime type parameter to date type

    Hello expert,
            I created crystal report by oracle procedure directly ,   but a date parameter for this procedure is mapped to datatime type parameter in crystal report, its format is dd/mm/yyyy hh:mm:ss.  instead of this datatime format, I need date format as "dd/mm/yyyy", but I found I can't change data type for this procedure parameter in crystal report.  I know I can't choose data type for procedure parameter if I use procedure in  command.  but over here, I have to use this procedure directly instead of using command as data connection for this report.  Can I change this procedure parameter for datetime type to date type in the crystal report. Apprecaite very much.

    You can get crystal to treat the datetime field as a date field by addressing it as 
    date({datetime})
    when ever you refer to it. You may even be able to address your parameter as
    date({?datetimeparameter})
    Debi

Maybe you are looking for

  • In credit memo request " WBS element"

    hi, while creating credit memo request in va01  it is asking  complete data  "WBS Element" in item data  accounting mgmt  it has WBS element  .i think its not relevant for SD Regards kiran.c

  • Adding unrecognized printer

    I am attempting to get my iMac G5 (10.3.9 OS) to recognize an hp 11p laserjet printer. Connection via a parallel to USB cable. Printer not on Apple list. hp website no help. I would appreciate any comment or help. Thanks!

  • Bugs in Safari for Windows XP!

    When I installed Safari, everything went smoothly, but when it started up, it looks very different from the Mac OS 10.3.9 version! the apple safari page is missing all of the text, and there is no menu bar, and the menu options are missing! anyone el

  • Sync iPad using iCloud

    I've sync my iPad using iCloud and it seems that my contacts hasn't transferred from my iPhone to ipad. Help please

  • '24 Track Recording' - all channels peak at 3db

    It seems that if I start a new song with the '24 Track Recording' template, all my audio and instrument channels peak at 3db. Is that normal? I checked and it doesn't matter whether the played back file is 24 or 16 bit. How do I change it so that it