15d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao/* 25d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Copyright (C) 2008 The Android Open Source Project 35d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * 45d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Licensed under the Apache License, Version 2.0 (the "License"); 55d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * you may not use this file except in compliance with the License. 65d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * You may obtain a copy of the License at 75d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * 85d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * http://www.apache.org/licenses/LICENSE-2.0 95d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * 105d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Unless required by applicable law or agreed to in writing, software 115d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * distributed under the License is distributed on an "AS IS" BASIS, 125d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * See the License for the specific language governing permissions and 145d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * limitations under the License. 155d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao */ 165d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao 175d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaopublic class StaticField { 185d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static boolean mBoolean1, mBoolean2; 195d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static byte mByte1, mByte2; 205d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static char mChar1, mChar2; 215d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static short mShort1, mShort2; 225d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static int mInt1, mInt2; 235d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static float mFloat1, mFloat2; 245d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static long mLong1, mLong2; 255d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static double mDouble1, mDouble2; 265d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static volatile long mVolatileLong1, mVolatileLong2; 275d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao 285d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static void run() { 295d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao assignFields(); 305d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao checkFields(); 315d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao } 325d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao 335d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static void assignFields() { 345d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao System.out.println("StaticField assign..."); 355d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mBoolean1 = true; 365d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mBoolean2 = false; 375d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mByte1 = 127; 385d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mByte2 = -128; 395d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mChar1 = 32767; 405d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mChar2 = 65535; 415d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mShort1 = 32767; 425d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mShort2 = -32768; 435d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mInt1 = 65537; 445d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mInt2 = -65537; 455d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mFloat1 = 3.1415f; 465d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mFloat2 = -1.0f / 0.0f; // -inf 475d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mLong1 = 1234605616436508552L; // 0x1122334455667788 485d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mLong2 = -1234605616436508552L; 495d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mDouble1 = 3.1415926535; 505d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mDouble2 = 1.0 / 0.0; // +inf 515d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mVolatileLong1 = mLong1 - 1; 525d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao mVolatileLong2 = mLong2 + 1; 535d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao } 545d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao 555d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao public static void checkFields() { 565d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao System.out.println("StaticField check..."); 57795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mBoolean1); 58795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(!mBoolean2); 59795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mByte1 == 127); 60795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mByte2 == -128); 61795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mChar1 == 32767); 62795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mChar2 == 65535); 63795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mShort1 == 32767); 64795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mShort2 == -32768); 65795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mInt1 == 65537); 66795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mInt2 == -65537); 67795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mFloat1 > 3.141f && mFloat2 < 3.142f); 68795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mFloat2 < mFloat1); 69795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mLong1 == 1234605616436508552L); 70795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mLong2 == -1234605616436508552L); 71795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mDouble1 > 3.141592653 && mDouble1 < 3.141592654); 72795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mDouble2 > mDouble1); 73795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mVolatileLong1 == 1234605616436508551L); 74795d78f4d04c8d007bf2bdf2ed4131379bcf19c7jeffhao Main.assertTrue(mVolatileLong2 == -1234605616436508551L); 755d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao } 765d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao} 77