Autoboxing

Little bug?

Have:

Boolean b = true;

Convert to boolean intention generates:

Boolean b = Boolean.valueOf(true);

should generate:

Boolean b = Boolean.TRUE;

Thx for the plugin!!!

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

0
Avatar
Permanently deleted user

Dani wrote:

Little bug?

Have:

Boolean b = true;

Convert to boolean intention generates:

Boolean b = Boolean.valueOf(true);

should generate:

Boolean b = Boolean.TRUE;

Thx for the plugin!!!

Thanks for suggestion, I would call it RFE then a bug. :)

You can download a new version of the plugin.
/kesh

0
Avatar
Permanently deleted user

On Wed, 25 Jun 2003 12:18:03 -0400, kesh <dummy@dummy.com> wrote:

Dani wrote:

>
>> Little bug?
>>
>> Have:
>>
>> Boolean b = true;
>>
>> Convert to boolean intention generates:
>>
>> Boolean b = Boolean.valueOf(true);
>>
>> should generate:
>>
>> Boolean b = Boolean.TRUE;
>>
>> Thx for the plugin!!!
>>

Thanks for suggestion, I would call it RFE then a bug. :)

>

You can download a new version of the plugin.
/kesh

>
>

Wow, really fast. Many thx.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

0
Avatar
Permanently deleted user


If you're going to put in that optimization, calling Boolean.valueOf() is a better solution than allocating a new Boolean. It's a static method that does just what you would expect, testing it's value and returning Boolean.TRUE or Boolean.FALSE, as appropriate. No memory allocation needed.

0
Avatar
Permanently deleted user

Whoops, I'm an idiot. I had an old version where you used new Boolean(). Downloading the new one new.

Great plugin, BTW.

0
Avatar
Permanently deleted user

If you're going to put in that optimization, calling
Boolean.valueOf() is a better solution than
allocating a new Boolean. It's a static method that
does just what you would expect, testing it's value
and returning Boolean.TRUE or Boolean.FALSE, as
appropriate. No memory allocation needed.


Boolean.valueOf() is better but it's Java 1.4 specific so it won't compile with 1.3.


Timur

0
Avatar
Permanently deleted user

Timur Zambalayev wrote:

>>If you're going to put in that optimization, calling
>>Boolean.valueOf() is a better solution than
>>allocating a new Boolean. It's a static method that
>>does just what you would expect, testing it's value
>>and returning Boolean.TRUE or Boolean.FALSE, as
>>appropriate. No memory allocation needed.


Boolean.valueOf() is better but it's Java 1.4 specific so it won't compile with 1.3.


Timur


Good point. I've uploaded a new version of the plugin which fixes this
problem. Now Boolean.valueOf method is used only when the project's JDK
has version 1.4.x or higher.

Thanks,
/kesh

0
Avatar
Permanently deleted user

Good point. I've uploaded a new version of the plugin which fixes this
problem. Now Boolean.valueOf method is used only when the project's JDK
has version 1.4.x or higher.


Jus't for curiosity what did you use?

Boolean boo = new Boolean(b);

or

Boolean boo = b ? Boolean.TRUE : Boolean.FALSE;


I can't say that I really care for either one, but the second one doesn't
create a new object.

If I really needed it, I would create:

public final class Booleans {
public static Boolean valueOf(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}
}

I created several utility classes - Dates, Strings, ... - to do things like
this.


0

请先登录再写评论。