Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclass final class (Boolean) ?



There is no way "around". The whole idea of "final" is to prevent you form modifying class behavior in any shape or form.
And is, in my opinion, idiotic. If there's a good reason there might be a problem, it should be documented rather than taking the 'punt' way out and making it final.

The reason Boolean is final (along with Float, Integer, Long, Char, etc.) is because it exists solely as a wrapper for a primitive type who's behavior is 'built into' Java.


Why don't you create proxy class which will wrap around Boolean and encapsulate your special behavior in this class letting Boolean object do the rest?
Yes, I could do that, but I really don't want to because it's ugly and gross, and if my object gets passed to a regular boolean with equals(), it might fail (not sure how it would react).

I think it would be uglier and grosser to subclass a primitive type wrapper just to obtain some minor formatting capability.


Ultimately, the code behind the scenes is going to be nicer with a primitive boolean value to evaluate, so why not just create some method (sorry, I'm not familiar with WebObjects) that will evaluate the input string and give you a primitive boolean? Seems like you just want something like return myInputString.equalsIgnoreCase("Y").

Also, why have an interface where a boolean value is represented by a String at all? Can't you use a checkbox or radio button that was designed to have exactly two discrete states?

Just my two cents...

- Erik Mattheis
  email@hidden

On Aug 27, 2006, at 10:28 AM, Ken Anderson wrote:

OK, I'm a little annoyed here because I find the whole concept of 'final' to be ridiculous.

I would like to subclass Boolean so that I can initialize it (class method) with a short string (valueOf:"t" instead of valueOf:"f") and also to return "t" and "f" for toString (or some other method like toShortString()).

Unfortunately, java.lang.Boolean is marked as final. Is there any way to get around that?

To give a little background, I would like to have a custom WebObjects type where I can declare the factory method to create the instance, and the method to call to get back the string instance. I want to make it a single character so that I can use a string field with length=1 instead of length=5 (saving a lot of space).

Oh, and yet another reason I want categories from Objective-C in Java...

Thanks,
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Subclass final class (Boolean) ? (From: Ken Anderson <email@hidden>)
 >Re: Subclass final class (Boolean) ? (From: Andrei Tchijov <email@hidden>)
 >Re: Subclass final class (Boolean) ? (From: Ken Anderson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.