>How to create new String having one char. Is it really only way to
>create new char array that has length one and using it create string?

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
>> How to create new String having one char. Is it really only way to
>> create new char array that has length one and using it create string?
[quoted text clipped - 8 lines]
> float Cvt.tofloat ( int i );
> Float Cvt.toFloat ( long l );
I understand why you did it, but the lack of camel case is jarring (no pun
intended). Besides, with autoboxing you don't need two versions:
float f = Cvt.toFloat( int i );
Float fc = Cvt.toFloat( int i );
Then again,
float f = i;
works just fine.
As for String conversions, I don't understand what you mean by the
"irregularity" at all. The String class has valueOf() overloads for all the
primitive types. The primitive type wrapper classes except Character have
valueOf( String ) overloads. It's hard to be more regular than that, unless
you insist on "remedying" the sole exception of Character, and I suspect that
one is due to the special relationship between Strings and chars and the
existence of String.charAt().
It's not worth running around Jericho's barn to wind up where I'm already
standing.

Signature
Lew
Mark Space - 24 Mar 2008 17:09 GMT
>> double Cvt.todouble( String s );
>> float Cvt.tofloat ( int i );
>> Float Cvt.toFloat ( long l );
> float f = Cvt.toFloat( int i );
> Float fc = Cvt.toFloat( int i );
I don't find either of these to be all that readable. In Roedy's
example, just the change in case is easy for my old eyes to miss. In
your case, overloading functions always runs the risk of calling the
wrong function on accident. (Say if the compiler is the one choosing
which function to call, how certain are you it calls the one you thought
it would?)
I think I'd make the function name more explicit, and skip the overloading.
float f = Cvt.toPrimitiveFloat( int i );
Float f2 = Cvt.toFloat( int i );
Or something like that. The idea of readability is key here.
Owen Jacobson - 24 Mar 2008 17:42 GMT
> >> double Cvt.todouble( String s );
> >> float Cvt.tofloat ( int i );
[quoted text clipped - 9 lines]
> which function to call, how certain are you it calls the one you thought
> it would?)
The whole point of Lew's post is that there is no overloading, as the
language already provides a feature that obviates the need for it. In
this case, there is a single method
public static float toFloat (int i)
In the second case, the returned float is being automatically boxed to
a Float by the compiler, freeing the programmer from having to write a
second method.
(Futhermore, Java forbids programmers from overloading by return type
only...)
-o
Mark Space - 24 Mar 2008 19:49 GMT
> (Futhermore, Java forbids programmers from overloading by return type
> only...)
Oh, good point. I didn't realize that.
Roedy Green - 24 Mar 2008 18:39 GMT
>Then again,
>
> float f = i;
>
>works just fine.
that's the problem. the lack of predictability and regularity. You
need something a newbie can use mindlessly. A decent optimiser
should inline them all so the final code would be just that.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Eric Sosman - 24 Mar 2008 19:16 GMT
>> Then again,
>>
[quoted text clipped - 5 lines]
> need something a newbie can use mindlessly. A decent optimiser
> should inline them all so the final code would be just that.
Neither newbies nor roedies[*] should be encouraged
to write code mindlessly.
[*] Needed a word connoting uncommon breadth and depth
of experience, the opposite of "newbie." For the sake of
sentence punch, wanted a two-syllable word ending in "-ies"
to highlight the contrast; this was the best I could find.

Signature
Eric.Sosman@sun.com
John W. Kennedy - 24 Mar 2008 22:56 GMT
>> Then again,
>>
[quoted text clipped - 5 lines]
> need something a newbie can use mindlessly. A decent optimiser
> should inline them all so the final code would be just that.
You're on the road to reinventing PL/I.

Signature
John W. Kennedy
"Only an idiot fights a war on two fronts. Only the heir to the throne
of the kingdom of idiots would fight a war on twelve fronts"
-- J. Michael Straczynski. "Babylon 5", "Ceremonies of Light and Dark"
Roedy Green - 24 Mar 2008 18:40 GMT
>As for String conversions, I don't understand what you mean by the
>"irregularity" at all. The String class has valueOf() overloads for all the
[quoted text clipped - 3 lines]
>one is due to the special relationship between Strings and chars and the
>existence of String.charAt().
have a look at all the various conversions at
http://mindprod.com/applet/converter.html
There are pockets of regularity, but overall it drives newbies to
distraction.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 24 Mar 2008 19:28 GMT
>I understand why you did it, but the lack of camel case is jarring (no pun
>intended). Besides, with autoboxing you don't need two versions:
>
> float f = Cvt.toFloat( int i );
> Float fc = Cvt.toFloat( int i );
you can't quite to do that e.g.
boolean isBig = ctv.toFloat( i ).isInfinite();
I don't think autoboxing would be smart enough to handle that.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 25 Mar 2008 04:11 GMT
> Float Cvt.toFloat ( long l );
Lew wrote,
>> Besides, with autoboxing you don't need two versions:
>>
>> float f = Cvt.toFloat( i );
>> Float fc = Cvt.toFloat( i );
> you can't quite to do that e.g.
>
> boolean isBig = ctv.toFloat( i ).isInfinite();
>
> I don't think autoboxing would be smart enough to handle that.
Works fine here:
package testit;
public class Boxer
{
public static Float toFloat( int in )
{
return (float) in;
}
public static Float toFloat( long in )
{
return (float) in;
}
public static void main(String[] args)
{
int in = 17;
boolean isBig = toFloat( in ).isInfinite();
System.out.println( "Is "+ in +" big? "+ isBig );
long ln = 4000000000L;
isBig = toFloat( ln ).isInfinite();
System.out.println( "Is "+ ln +" big? "+ isBig );
}
}

Signature
Lew
Roedy Green - 25 Mar 2008 05:08 GMT
> isBig = toFloat( ln ).isInfinite();
Good. that gets rid of the need to distinguish between toFloat and
tofloat.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com