Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

In case of a generic enclosing type the question is: which instantiation of the generic type can or must be used as the scope qualifier?

0
Posted

In case of a generic enclosing type the question is: which instantiation of the generic type can or must be used as the scope qualifier?

0

The rule is that no instantiation can be used. The scope is qualified using the raw type. This is because there is only one instance of a static member per type. Example (of a generic type with static members): public final class Counted { public static final int MAX = 1024; public static class BeyondThresholdException extends Exception {} private static int count; public static int getCount() { return count; } private final T value; public Counted(T arg) throws BeyondThresholdException { value = arg; count++; if (count >= 1024) throw new BeyondThresholdException(); } public void finalize() { count–; } public T getValue() { return value; } } int m = Counted .MAX; // ok int k = Counted .MAX; // error int n = Counted .MAX; // error try { Counted[] array = null; array[0] = new Counted(10L); array[1] = new Counted(“abc”); } catch ( Counted .BeyondThresholdException e) { e.printStackTrace(); } System.out.println( Counted .getCount()); // ok System.out.println

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.