Superpackages and final

Neal Gafter neal at gafter.com
Wed Mar 24 02:02:22 UTC 2010


You could make the constructor module-private, so that the class can only be
extended within the module, and use public static factory methods to create
instances.  You don't need any special language support to do that.

On Tue, Mar 23, 2010 at 6:26 PM, Paulo Levi <i30817 at gmail.com> wrote:

> Do superpackages can mark exported classes as final?
>
> What do i mean is can i export a class "as final" instead of marking it
> final.
> I ask because in some situations separating a unusual object capability
> into a sub-type would be advantageous memory-wise, but the type has to be
> final, because of backward compatibility or design.
>
> I'm going to give a rather radical example from java.lang: String has a
> substring capability and it uses two int fields (of 3 + a char array) to do
> it, when it could return a private subclass of string on substring. It
> doesn't, besides serialization complications, i guess because string is
> designed not be extended for immutability concerns.
>
> Problem is final has no granularity, and is all or nothing, namespace-wise.
> Well, i asked the question, but i don't have much hope.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20100323/78ad6c93/attachment.html>


More information about the core-libs-dev mailing list