提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
返回给定的类(val)作为其自身;如果它等于默认的Class,则返回null。
/** * Copyright (C) 2011 Tom Spencer <thegaffer@tpspencer.com> * * This file is part of TAL. * * TAL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * TAL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TAL. If not, see <http://www.gnu.org/licenses/>. * * Note on dates: Year above is the year this code was built. This * project first created in 2008. Code was created between these two * years inclusive. */ //package com.nowjava; public class Main { /** * nowjava - 时代Java 提 供 **/ public static void main(String[] argv) throws Exception { Class val = String.class; Class defaultClass = String.class; System.out.println(getAnnotationClass(val, defaultClass)); } /** * Returns the given class (val) as itself or nulls if it * it is equal to the defaultClass. This is because you * cannot have null as default, so this method helps deal * with that. * * @param val The class * @param defaultClass The class that if above is equal to should null the result * @return The val, or null if it is equal to default */ public static Class<?>