"Naked" parameters in casts or instanceof operations.
数据类型转换或instance of操作中的“外露”参数。
In some cases, it may be sensible to use an instanceof check prior to doing a class cast.
在某些情况下,在做类型转换之前用instance of进行检查是有意义的。
The instanceof operator resolves to true if the given object is an instance of the given class.
如果给定对象是给定类的实例,则 instanceof操作符解析为真。
I could easily add support for reporting casts, instanceof tests, and catch blocks by implementing the appropriate methods in VerboseEditor.
通过在VerboseEditor中实现适当的方法,可以容易地增加对报告强制类型转换、instance of检查和catch块的支持。
You can test this using the instanceof operator, which returns true if the object is a member of the indicated class, as shown in Listing 14.
可以使用instance of操作符来测试这一点,如果对象是指定类的成员,则返回true,如清单14所示。
Similarly, instanceof checks on naked type parameters will result in an "unchecked" warning at compile time and the check will not occur as expected at runtime.
同样,对“外露”类型参数的instance of检查将在编译时产生“unchecked”警告,而且检查将不会如期在运行时进行。
Throwing an exception would not help in our case because we would then have to add instanceof checks in hasConsecutiveZeros to ensure that we didn't trigger the exception.
抛出一个异常在本例中帮不了什么忙,因为我们将不得不在hasConsecutiveZeros中添加instanceof 检查语句以确保我们没有触发异常。
The disadvantage of using instanceof checks in this fashion is that, if we were to add another subclass of Tree (such as, a LeafWithValue class), we would have to revise these instanceof checks.
以这种方式使用instance of检查语句的一个缺点是,如果我们要添加Tree的另一个子类(比如一个leafwithvalue类),我们将不得不修改这些instance of检查语句。
The disadvantage of using instanceof checks in this fashion is that, if we were to add another subclass of Tree (such as, a LeafWithValue class), we would have to revise these instanceof checks.
以这种方式使用instance of检查语句的一个缺点是,如果我们要添加Tree的另一个子类(比如一个leafwithvalue类),我们将不得不修改这些instance of检查语句。
应用推荐