| Author |
question on return type
|
ritwik roy
Greenhorn
Joined: May 13, 2005
Posts: 20
|
|
hi all Byte is a wrapper object, not a primitive. But in the code given below if we try to catch that wrapper object with the primitive 'int', then there will not be any error. why!!! class C1 { int m1() { Byte b=7; return b; } public static void main(String arg[]) { C1 c=new C1(); int p=c.m1(); System.out.println(p); } }
|
 |
Aurelio Jr. Pascual
Greenhorn
Joined: Sep 21, 2005
Posts: 2
|
|
|
thats the new feature of J2SE 5.0 called auto-boxing and auto-unboxing, before J2SE 5.0 that code will give a compiler error
|
 |
ritwik roy
Greenhorn
Joined: May 13, 2005
Posts: 20
|
|
hi!Aurelio what is this auto-boxing and auto-unboxing. It is applicable to all wrapper Objects and primitives or in some particular cases??? plz send some related links......
|
 |
Naresh Saw
Ranch Hand
Joined: Sep 03, 2005
Posts: 66
|
|
hi all if u people r preparing for scjp 1.4, plz don't use jdk1.5 because here this type of code will compile and run without error due to autoboxing and autounboxing. prior to jdk1.5 : this code Byte b = 26; //1 System.out.printlnn(b); //2 was an error but in jdk1.5 when we compile, the compiler automatically create an object of type Byte(called autoboxing). bye
|
naresh<br />SCJP 1.4(86%), SCWCD 1.4(78%)
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
|
|
Hi Ritwik! You can find about boxing and unboxing in JLS, here. I dont know under what circumstances these conversions are automatic and non-automatic. Any further links???
|
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by ritwik roy: ...plz send some related links......
Sun - Java 1.5 in a Nutshell
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
ritwik roy
Greenhorn
Joined: May 13, 2005
Posts: 20
|
|
thanks Naresh! i m preparing for scjp1.4 ,but i have been using jdk1.5 for the last 2 months. now my question is that suppose in the real exam(scjp1.4) i face such type of problem, then what should i do. go for the compiler error option.....or utilize this type of latest technology..... what r the other things which i have not got any error in jdk1.5 but will get if i use jdk1.4.. if u know some points, plz send me..
|
 |
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
|
|
|
No you should go for only "compiler error " if you are writing 1.4
|
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
|
 |
Naresh Saw
Ranch Hand
Joined: Sep 03, 2005
Posts: 66
|
|
|
srinivan is right. don't confuse with such question and keep in mind we r going for 1.4 not 1.5 dear.
|
 |
 |
|
|
subject: question on return type
|
|
|