Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2005

Tip: Looking for answers? Try searching our database.

Primitive int variable with MAX_VALUE

Thread view: 
Mark - 19 Jan 2005 16:30 GMT
Hello,

How do I create a primitive int variable which holds the largest value it
possibly can? I've tried this:

public Integer x = Integer.MAX_VALUE;
public int y = x.intValue();

... but I get an "Incompatible types" error. I can't work out if a) I can do
the operation in 1 graceful statement, or b) if not, how to create a new
Integer and assign the Integer.MAX_VALUE to it.

Thanks.

Mark
Mark - 19 Jan 2005 16:41 GMT
> How do I create a primitive int variable which holds the largest value it
> possibly can?

Bah! Looks like the following works:

public int y = Integer.MAX_VALUE;

Talk about not seeing the wood for the trees...

Mark
Boudewijn Dijkstra - 19 Jan 2005 16:46 GMT
> Hello,
>
[quoted text clipped - 7 lines]
> do the operation in 1 graceful statement, or b) if not, how to create a new
> Integer and assign the Integer.MAX_VALUE to it.

I don't know what planet you are from, but out here we just do:

int x = Integer.MAX_VALUE;

because Integer.MAX_VALUE is declared as an int, not as an object of Integer.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.