About Question enthuware.ocajp.i.v8.2.1247 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
java_learner
Posts: 6
Joined: Sun Feb 05, 2017 3:42 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1247 :

Post by java_learner »

In the answer to this question it says:
A narrowing primitive conversion may be used if all of the following conditions are satisfied:

1. The expression is a constant expression of type int.
But I tried the following and it worked without problems:

Code: Select all

final char c = 5;
byte b = c;
I also tried

Code: Select all

final short s = 5;
So it seems to me that the constant expression is also allowed to be char or short. It doesn't have to be int.

Am I missing something?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1247 :

Post by admin »

You are right. It doesn't have to be an int but can be any integral type i.e. int, byte, char, or short. As long as the value value of the constant expression is representable in the target type of the variable, it can be implicitly narrowed to the target variable.

I have updated the explanation.

thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests