1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class StaticField { 18 public static boolean mBoolean1, mBoolean2; 19 public static byte mByte1, mByte2; 20 public static char mChar1, mChar2; 21 public static short mShort1, mShort2; 22 public static int mInt1, mInt2; 23 public static float mFloat1, mFloat2; 24 public static long mLong1, mLong2; 25 public static double mDouble1, mDouble2; 26 public static volatile long mVolatileLong1, mVolatileLong2; 27 run()28 public static void run() { 29 assignFields(); 30 checkFields(); 31 } 32 assignFields()33 public static void assignFields() { 34 System.out.println("StaticField assign..."); 35 mBoolean1 = true; 36 mBoolean2 = false; 37 mByte1 = 127; 38 mByte2 = -128; 39 mChar1 = 32767; 40 mChar2 = 65535; 41 mShort1 = 32767; 42 mShort2 = -32768; 43 mInt1 = 65537; 44 mInt2 = -65537; 45 mFloat1 = 3.1415f; 46 mFloat2 = -1.0f / 0.0f; // -inf 47 mLong1 = 1234605616436508552L; // 0x1122334455667788 48 mLong2 = -1234605616436508552L; 49 mDouble1 = 3.1415926535; 50 mDouble2 = 1.0 / 0.0; // +inf 51 mVolatileLong1 = mLong1 - 1; 52 mVolatileLong2 = mLong2 + 1; 53 } 54 checkFields()55 public static void checkFields() { 56 System.out.println("StaticField check..."); 57 Main.assertTrue(mBoolean1); 58 Main.assertTrue(!mBoolean2); 59 Main.assertTrue(mByte1 == 127); 60 Main.assertTrue(mByte2 == -128); 61 Main.assertTrue(mChar1 == 32767); 62 Main.assertTrue(mChar2 == 65535); 63 Main.assertTrue(mShort1 == 32767); 64 Main.assertTrue(mShort2 == -32768); 65 Main.assertTrue(mInt1 == 65537); 66 Main.assertTrue(mInt2 == -65537); 67 Main.assertTrue(mFloat1 > 3.141f && mFloat2 < 3.142f); 68 Main.assertTrue(mFloat2 < mFloat1); 69 Main.assertTrue(mLong1 == 1234605616436508552L); 70 Main.assertTrue(mLong2 == -1234605616436508552L); 71 Main.assertTrue(mDouble1 > 3.141592653 && mDouble1 < 3.141592654); 72 Main.assertTrue(mDouble2 > mDouble1); 73 Main.assertTrue(mVolatileLong1 == 1234605616436508551L); 74 Main.assertTrue(mVolatileLong2 == -1234605616436508551L); 75 } 76 } 77