SCJP: cannot expand and then field, but you can insert and then expand

I am studying the SCJP exam and I have a problem that I can’t wrap my head around.

The book says that you cannot expand and then insert a box, but you can insert and then expand. An example for the impossibility of input is a method that expects Long and a method called by byte.

Their explanation:

Think about it ... if he tries to insert first, the byte would be converted to byte. Now we are back to trying to expand the byte to long, and of course, the IS-A test fails.

But it sounds like a box, and then expanding and not expanding, and then a box for me.

Can someone clarify the whole box and expand, as well as increase the size and window for me, because, since it is standing, the book is not entirely clear on this issue.

Edit: To clarify: I'm talking about Sun SCJP certified programmer pages 252 and 25 for java book 6. http://books.google.be/books?id=Eh5NcvegzMkC&pg=PA252#v=onepage&q&f=false

+4
source share
5 answers

the language is confused.

:
byte → Byte → Long
Byte Long is-a.
, :
byte → long → Long
(, - ). , .

, , :
byte → Byte →
Byte is-Object.

2 :

toLong ( x)
toObject ( x)
b = 5;

:
toLong ();
// b → (b) → ( (b)) .
AND byte → long → Long - .

:
toObject (b);
// b → (b) → ( (b)) .

+4

, " " , (. 249 SCJP):

Java 5 , , , , , ,

+4

, , . , (bytebyte). - byte, Double, Float, Integer, Long Short (IS-A). A Long byte .

, (byteLong), (LongLong).

+3

, , , . , , , , , .

, , , , , , , .. . , , --, IS-A Numeric ( )

+1

This is not an extension because the byte does not fit into Long. That is why it does not work.

You can insert in bytes and then expand to Objector Number.

As your book says:

we will go back to try to expand bytes to long


In your case, I suppose the code is as follows:

byte b = 1;
Long l = b;

b is changed to Byte(box first), but cannot be changed to Longbecause the byte is not a subclass Long.

In the following steps:

byte b = 1;
Byte byteB = b; //works
Long l = byteB; //doesn't work
0
source

All Articles