Java tutorial
//package com.java2s; /* * Javassist, a Java-bytecode translator toolkit. * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. Alternatively, the contents of this file may be used under * the terms of the GNU Lesser General Public License Version 2.1 or later, * or the Apache License Version 2.0. * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. */ public class Main { /** * <code>Class</code> objects representing primitive types. */ public static final Class[] primitiveTypes = { Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE }; /** * Returns an index for accessing arrays in this class. * * @throws RuntimeException if a given type is not a primitive type. */ public static final int typeIndex(Class type) { Class[] list = primitiveTypes; int n = list.length; for (int i = 0; i < n; i++) if (list[i] == type) return i; throw new RuntimeException("bad type:" + type.getName()); } }