|
|
Re: Force compiler to emit checkcast for upcast [message #1738814 is a reply to message #1738766] |
Mon, 25 July 2016 07:35 |
Andreas Sewe Messages: 111 Registered: June 2013 |
Senior Member |
|
|
Stephan Herrmann wrote on Sat, 23 July 2016 11:03You are relying on the fact that pre 3.10 this method will never get called, and you just want to avoid verification errors, is that it?
Yes, that's it; I know that a pre3.10 JDT's ASTNode.accept(ASTVisitor) will never visit a LambdaExpression, but I need to make sure that MyVisitor can load without the JVM trying to resolve LambdaExpression during the verification of the MyVisitor.visit(LambdaExpression) method.
Quote:Would the following kludge work?
Object o = node:
helper( (Expression) o);
(No, the compiler has no such option for inserting unnecessary casts).
That does the trick. Thank you.
FYI, JDT Core is a nice API to work with when you still have support older versions of the JDT in the same codebase, as code like the following (and the aforementioned visit methods) only requires a new JDT to compile, but not to run:
switch (node.getNodeType)) {
case ASTNode.LAMBDA_EXPRESSION:
LambdaExpression lambda = (LambdaExpression) node;
// Do JDT 3.10+ stuff with lambda
break;
}
It's quite well designed in that respect. Kudos!
|
|
|
Powered by
FUDForum. Page generated in 0.04794 seconds