Unchecked cast unchecked?
Archie Cobbs
archie.cobbs at gmail.com
Tue Oct 29 21:30:24 UTC 2024
Question: Should this program generate an unchecked cast warning?
import java.lang.invoke.VarHandle;
class VarHandleCast<V> {
VarHandle vh;
V method(Object obj) {
return (V)vh.getAndSet(this, obj); // unchecked cast?
}
}
Currently, it does not.
Presumably that has something to do with this code in Types.java but I'm
not sure why this would mean there should be no warning:
/**
* A polymorphic signature method (JLS 15.12.3) is a method that
* (i) is declared in the java.lang.invoke.MethodHandle/VarHandle
classes;
* (ii) takes a single variable arity parameter;
* (iii) whose declared type is Object[];
* (iv) has any return type, Object signifying a polymorphic return
type; and
* (v) is native.
*/
public boolean isSignaturePolymorphic(MethodSymbol msym) {
List<Type> argtypes = msym.type.getParameterTypes();
return (msym.flags_field & NATIVE) != 0 &&
(msym.owner == syms.methodHandleType.tsym || msym.owner ==
syms.varHandleType.tsym) &&
argtypes.length() == 1 &&
argtypes.head.hasTag(TypeTag.ARRAY) &&
((ArrayType)argtypes.head).elemtype.tsym ==
syms.objectType.tsym;
}
Thanks,
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20241029/d73cd512/attachment.htm>
More information about the compiler-dev
mailing list