Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

conditional operator and nulltype

807589Oct 27 2008 — edited Oct 27 2008
hi,

i have a little problem, it's actually not really a problem, im just curious. i have the following testclass
public class Test{
  public static void main(String[] args) {
    Double a = false? 1.00: (Double)null; // nullpointer (A)
    Double b = false? 1.00: null;  // works (B)
  }
}
when line (A) is uncommented a NullPointerException is thrown and i have no idea why.
when i comment out line (A), line (B) works. because the type of the conditional operator is of the other if one of them is NullType.

so not really a problem because it's better to use (B) but i still want to know why (A) doesn't work.

Edited by: creichlin on Oct 27, 2008 12:15 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2008
Added on Oct 27 2008
1 comment
22 views