Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*   Copyright (C) 2013-2014 Computer Sciences Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. */

import java.lang.reflect.Field;

public class Main {
    /**
     * Determines if the field is an instance of a primitive.
     * <ul><li>String.class</li>
     * <li>Boolean.class <b>OR</b> boolean.class</li>
     * <li>Integer.class <b>or</b> int.class</li>
     * <li>Double.class <b>or</b> double.class</li>
     * <li>Float.class <b>or</b> float.class</li></ul>
     * @param field The field to verify
     * @return The true if primitive
     */
    public static boolean isPrimitive(Field field) {

        if (field == null) {
            return false;
        }

        if (field.getType() == String.class) {
            return true;
        } else if (field.getType() == Boolean.class || field.getType() == boolean.class) {
            return true;
        } else if (field.getType() == Integer.class || field.getType() == int.class) {
            return true;
        } else if (field.getType() == Double.class || field.getType() == double.class) {
            return true;
        } else if (field.getType() == Float.class || field.getType() == float.class) {
            return true;
        }
        return false;
    }
}