Nested generics (limited?)

  • Thread starter Thomas G. Marshall
  • Start date
T

Thomas G. Marshall

Given the following code, I've nested generics in a common way.

SimpleClass<ArrayList<String>>

Is there a limit to the nesting of such structures? a OF b OF c OF d
(repeat as needed) :)

I'm looking for it in the spec, and I 1. am crummy at looking for things in
the spec, and 2. cannot find it.

Thanks,

Thomas



<code>
public class Simple2
{
interface SimpleInterface<E>
{
void set(E x);
E get();
}

// Tried it with F...
static class SimpleClass<F> implements SimpleInterface<F>
{
F thing;

public void set(F x)
{
thing = x;
}

public F get()
{
return thing;
}
}

public static void main(String[] args)
{
{
SimpleClass<String> simple = new SimpleClass<String>();
simple.set("hello");
System.out.println(simple.get());
}

{
// Tried simpleclass OF arraylist OF string
SimpleClass<ArrayList<String>> simple
= new SimpleClass<ArrayList<String>>();
ArrayList<String> al = new ArrayList<String>();
al.add("hello");
al.add("there");
al.add("again");
simple.set(al);
System.out.println(simple.get());
}

{
// Tried simpleclass OF arraylist OF Integer
SimpleClass<ArrayList<Integer>> simple
= new SimpleClass<ArrayList<Integer>>();
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(new Integer(5));
al.add(new Integer(6));
al.add(new Integer(7));
simple.set(al);
System.out.println(simple.get());
}
}
}
</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top