Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper class constructors

 
Neha Monga
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!

Compiler complains for the following code -->

public class XXX {
public static void main(String args[]) {
byte a = 10;
Byte x = new Byte(a);
Byte y = new Byte(11);//compiler complains
System.out.println(x.compareTo(y));
}
}


Why the compiler does not complain for the following code -->

public class ZZZ {
public static void main(String args[]) {
Float f = new Float(32D);//compiler does not complain
System.out.println(f);
}
}

pls clarify..Thanks
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you by any chance looked at the API for these classes?
 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just go through the java doc.
In your first code 11 is "int" that is default type for integer type and there is constructor defined which take "int" and "int" is not automatically converted into byte .
if you change your code to
Byte y = new Byte((byte)11);// compiles fine

second code is perfectly fine
there is a constructor defined
Float(double value) in API just go through it.

Regards,

Abdul Mohsin
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check with the javaDoc,
there is no costructor for new Byte(int value)
but, there is a constructor for new Float(double value).
 
Neha Monga
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...i found my answer in API...

thanks
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"krishna" while we appreciate your responses to the questions on this forum, you are getting near the post count limit where we close your access to JavaRanch for disregarding our JavaRanch Naming Policy. So please change your display name immediately (in brief: <first name><space><family name> ;) .

Thanks
-Barry

(close)
[ May 23, 2007: Message edited by: Barry Gaunt ]
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed my dispaly name.
Is there any post count limit here? I really don't know that
if yes, can you tell me or give the link where can i get that information.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by krishna:
I have changed my dispaly name.
Is there any post count limit here? I really don't know that
if yes, can you tell me or give the link where can i get that information.


You do not need to know about the post count exact limit when we lock your account when it has an invalid display name. You have just to worry about getting your display name changed.

Your display name seems to still be "krishna", what did you change it too?
[ May 23, 2007: Message edited by: Barry Gaunt ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barry

Is there any limits on the number of posts ? If so on what frequency its taken into account?

If it really matters, can you please redirect us to the page where we will be educated on it!

Thank you.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

[RM]:Is there any limits on the number of posts ? If so on what frequency its taken into account?

I think, no I'm sure Barry was referring to the fact that incase you do have a display name that does not meets the Javaranch standards then your account could be deleted.

[EDIT] Had forgot to add the does not words in my orignal post.
[ May 24, 2007: Message edited by: Anupam Sinha ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anupam Sinha:
Hi

[RM]:Is there any limits on the number of posts ? If so on what frequency its taken into account?

I think, no I'm sure Barry was referring to the fact that incase you do have a display name that does not meets the Javaranch standards then your account could be deleted.


Exactly.
[ May 29, 2007: Message edited by: Barry Gaunt ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic