1

该方法定义如下:

public static void checkNotNull<T extends Throwable>(Object value, String name, Class<T> exceptionClass) 
{

}

然后编译器抛出一些错误:

**此行有多个标记

- void is an invalid type for the variable checkNotNull
- Duplicate field ValidationUtility.value
- Syntax error on token ">", Identifier expected after this token
- The type Class is not generic; it cannot be parameterized with 
 arguments <T>
- The type Class is not visible
- Duplicate field ValidationUtility.exceptionClass
- T cannot be resolved to a type
- Syntax error, insert ";" to complete FieldDeclaration
- Duplicate field ValidationUtility.String**

有什么问题吗?请帮帮我,谢谢。

4

3 回答 3

1

void checkNotNull<T extends Throwable>(...,Class<T> exceptionClass)是错误的语法。它应该是<T extends Throwable>void checkNotNull(...,Class<T> exceptionClass)

public static <T extends Throwable> void checkNotNull(Object value, String name, 
                                                      Class<T> exceptionClass) {}
于 2012-09-27T11:16:33.910 回答
0

<T extends Throwable>在作废之前声明。

public static <T extends Throwable> void checkNotNull(Object value, String name,
Class<T> exceptionClass) {}

可以参考泛型教程

JLS#8.4。方法声明

MethodHeader:
     MethodModifiersopt TypeParametersopt Result MethodDeclarator Throwsopt
于 2012-09-27T11:15:49.557 回答
0
public static <T extends Throwable> void checkNotNull(Object value, String name, Class<T> exceptionClass) 
{

}
于 2012-09-27T11:15:55.643 回答