Created
September 4, 2012 13:20
-
-
Save khotyn/3621097 to your computer and use it in GitHub Desktop.
Revisions
-
khotyn created this gist
Sep 4, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ /** * Conditional Expression Test. The result is * * <pre> * 114.0 * class java.lang.Double * </pre> * * So why the result is 114.0, the ASCII value of <code>'r'</code>? First, the * <code>new Double(0)</code> is convert to primary type <code>double</code>, * and if there is a <code>double</code> in the expression, other primary type * will be converted to <code>double</code>. After that, since the conditional * expression result is a <code>Object</code>, so double is boxed to * <code>Double</code>. * * @author khotyn * */ public class ConditionalExpressionTest { public static void main(String[] args) { Object obj = true ? 'r' : new Double(0); System.out.println(obj); System.out.println(obj.getClass()); } }