1 /* 2 * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4869233 4872709 4868735 4921949 4921209 4965701 4934916 4975565 4974939 27 * @summary Boxing/unboxing positive unit and regression tests 28 * @author gafter 29 */ 30 31 public class Boxing1 { 32 33 static Boolean _Boolean = true; 34 static boolean _boolean = _Boolean; 35 36 static Byte _Byte = (byte)3; 37 static byte _byte = _Byte; 38 39 static Character _Character = 'a'; 40 static char _char = _Character; 41 42 static Short _Short = (short)4; 43 static short _short = _Short; 44 45 static Integer _Integer = 5; 46 static int _int = _Integer; 47 48 static Long _Long = 12L; 49 static long _long = _Long; 50 51 static Float _Float = 1.2f; 52 static float _float = _Float; 53 54 static Double _Double = 1.34; 55 static double _double = _Double; 56 57 public static void main(String[] args) { 58 _Double = _Integer + _Integer + 0.0d; 59 if (_Double != 10) throw new Error(); 60 61 _Integer = 2; 62 _float = _Integer; 63 if (_float != 2.0f) throw new Error(); 64 65 _int = 12; 66 _Float = _int + 0.0f; 67 if (_Float != 12.0f) throw new Error(); 68 69 _Integer = 8; 70 _float = (float)_Integer; 71 if (_float != 8.0f) throw new Error(); 72 73 _int = 9; 74 _Float = (Float)(_int + 0.0f); 75 if (_Float != 9.0f) throw new Error(); 76 77 if (_Boolean) ; else throw new Error(); 78 if (!_Boolean) throw new Error(); 79 80 if (_Integer >= _Long) throw new Error(); 81 82 _Character = 'a'; 83 String s1 = ("_" + _Character + "_").intern(); 84 if (s1 != "_a_") throw new Error(s1); 85 86 /* assignment operators don't work; see 4921209 */ 87 if (_Integer++ != 8) throw new Error(); 88 if (_Integer++ != 9) throw new Error(); 89 if (++_Integer != 11) throw new Error(); 90 if ((_Integer += 3) != 14) throw new Error(); 91 if ((_Integer -= 3) != 11) throw new Error(); 92 93 Integer i = 0; 94 i = i + 2; 95 i += 2; 96 if (i != 4) throw new Error(); 97 98 int j = 0; 99 j += i; 100 if (j != 4) throw new Error(); 101 102 Integer a[] = new Integer[1]; 103 a[0] = 3; 104 a[0] += 3; 105 if (a[0] != 6) throw new Error(); 106 107 Froobie x = new Froobie(); 108 Froobie y = new Froobie(); 109 x.next = y; 110 x.next.i = 4; 111 x.next.i += 4; 112 if (--x.next.i != 7) throw new Error(); 113 if (x.next.i-- != 7) throw new Error(); 114 if (x.next.i != 6) throw new Error(); 115 116 boxIndex(); 117 boxArray(); 118 } 119 120 static void boxIndex() { 121 String[] a = { "hello", "world" }; 122 Integer i = 0; 123 System.out.println(a[i]); 124 } 125 126 static void boxArray() { 127 Integer[] a2 = { 0, 1, 2, 3 }; 128 for (int i : a2) 129 System.out.println(i); 130 } 131 132 static class Froobie { 133 Froobie next = null; 134 Integer i = 1; 135 } 136 137 static class Scott { 138 Integer i[]; 139 Integer j[]; 140 Integer k; 141 142 int q = i[j[k]]++; 143 } 144 145 class T4974939 { 146 void f() { 147 Byte b = 12; 148 Byte c = 'a'; 149 150 Short s = 'b'; 151 Short t = 12; 152 153 Character d = 12; 154 } 155 } 156 }