AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   Java (https://forums.alliedmods.net/showthread.php?t=182778)

Dr. McKay 04-13-2012 12:24

Java
 
Have to instantiate an object in order to format a number?

http://www.memecreator.org/static/im...emes/92773.jpg


Also,

http://www.memecreator.org/static/im...emes/92766.jpg

Jelle 04-13-2012 12:42

Re: Java
 
I get the feeling that you do not like Java.

Powerlord 04-13-2012 16:09

Re: Java
 
Quote:

Originally Posted by Dr. McKay (Post 1688266)
Have to instantiate an object in order to format a number?

If you don't like Java, why not just use C# or something else instead?

Dr. McKay 04-13-2012 16:11

Re: Java
 
Quote:

Originally Posted by Powerlord (Post 1688415)
If you don't like Java, why not just use C# or something else instead?

I'm in a Java class... (no pun intended)

Exolent[jNr] 04-13-2012 16:15

Re: Java
 
Quote:

Originally Posted by Dr. McKay (Post 1688416)
I'm in a Java class... (no pun intended)

http://cdn.overclock.net/5/59/480x32...here-38863.png

Powerlord 04-13-2012 16:27

Re: Java
 
Quote:

Originally Posted by Dr. McKay (Post 1688266)
Have to instantiate an object in order to format a number?

As a side note, you're not instantiating an object as much as asking the provider for the NumberFormat abstract class to do it for you. For that matter, having not looked at the SPI code for NumberFormat, it could easily cache the instances of the various NumberFormats for the default locale, so calling getInstance only gets you a reference to an already allocated object.

Personally, I think that'd be a dumb way to do it, but meh.

Anyway, I mentioned C# because it has .ToString overloads to do formatting on the various number types. Then again, all number types in C# are structs rather than primitives.

Dr. McKay 04-13-2012 17:20

Re: Java
 
I'm just not a huge fan of exclusively object-oriented programming.

I like my linear stuff...

Or at least the ability to use objects if I so choose.

Also,
Code:

NumberFormat format = new NumberFormat("###.##");
String formatted = format.format(100);

As opposed to
PHP Code:

$formatted number_format(1002); 


Powerlord 04-13-2012 17:37

Re: Java
 
Quote:

Originally Posted by Dr. McKay (Post 1688484)
I'm just not a huge fan of exclusively object-oriented programming.

Java is entirely object-oriented with the exception of its primitive variable types. C# is entirely object-oriented.

Not surprisingly, you use objects for nearly everything except for operators and keywords.

Quote:

Originally Posted by Dr. McKay (Post 1688484)
Or at least the ability to use objects if I so choose.
PHP Code:

$formatted number_format(1002); 


Don't even get me started about PHP.

Quote:

Originally Posted by Dr. McKay (Post 1688484)
Code:

NumberFormat format = new NumberFormat("###.##");
String formatted = format.format(100);


As a side note, that class on the right side should be DecimalFormat as NumberFormat is an abstract class.

Dr. McKay 04-13-2012 17:42

Re: Java
 
Quote:

Originally Posted by Powerlord (Post 1688497)
Don't even get me started about PHP.

lol, I love PHP.

Quote:

Originally Posted by Powerlord (Post 1688497)
As a side note, that class on the right side should be DecimalFormat as NumberFormat is an abstract class.

Yeah, I meant that...

Don't have the library of Java memorized, nor do I intend to. I'd much rather go and learn C++.


All times are GMT -4. The time now is 03:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.