Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: can I create an array in a parameterized class

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    91
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default can I create an array in a parameterized class

    lets say I want to create a parameterized class

    public class MySet<T extends Comparable> implements Set<T> {
     
        T[] n;
     
        MySet(T a)
        {
     
        }
     
    }

    is it possible to create an array of type <T> inside the class?


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    83
    My Mood
    Cynical
    Thanks
    3
    Thanked 9 Times in 9 Posts

    Default Re: can I create an array in a parameterized class

    What happens when you try?

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    91
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: can I create an array in a parameterized class

    Quote Originally Posted by Fubarable View Post
    What happens when you try?
    that's the problem I'm having. I don't know how to initialize a type <T> array. Also, I don't know the size of the array. Is it possible to do?

Similar Threads

  1. JAVA problem : Create a Fan Class
    By broo7198 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 9th, 2011, 12:23 AM
  2. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM
  3. Replies: 2
    Last Post: January 22nd, 2011, 10:20 PM
  4. Not Generic; cannot be parameterized
    By javaoo in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2010, 09:53 AM
  5. How to create a new object of another class within a method
    By davie in forum Object Oriented Programming
    Replies: 1
    Last Post: April 16th, 2010, 05:53 PM