is Primitive Assignable - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

is Primitive Assignable

Demo Code

/*/*from   w  ww .  j a v a  2 s  .  c o  m*/
 * Copyright (C) 2014 The Datarobot Authors
 *
 * 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.
 */
//package com.java2s;

public class Main {
     static boolean isPrimitiveAssignable(final Class<?> paramType,
            final Class<?> argType) {
        if (paramType.equals(java.lang.Boolean.TYPE)
                && argType.equals(java.lang.Boolean.class)) {
            return true;
        } else if (paramType.equals(java.lang.Integer.TYPE)
                && argType.equals(java.lang.Integer.class)) {
            return true;
        } else if (paramType.equals(java.lang.Character.TYPE)
                && argType.equals(java.lang.Character.class)) {
            return true;
        } else if (paramType.equals(java.lang.Float.TYPE)
                && argType.equals(java.lang.Float.class)) {
            return true;
        } else if (paramType.equals(java.lang.Double.TYPE)
                && argType.equals(java.lang.Double.class)) {
            return true;
        } else if (paramType.equals(java.lang.Long.TYPE)
                && argType.equals(java.lang.Long.class)) {
            return true;
        } else if (paramType.equals(java.lang.Short.TYPE)
                && argType.equals(java.lang.Short.class)) {
            return true;
        }

        return false;
    }
}

Related Tutorials