R
Roedy Green
Is it possible to write code with this meaning without compiler
warning messages? Where Macro is the name of an interface.
I understand the code is just using a plain Class object, and hence as
no idea if forName actually returned a Class object that implements
Macro. I am using the cast here is the C++ , "trust me" sense.
Ideally I would like the cast to fail if the class does not implement
Macro.
// e.g. "com.mindprod.htmlmacros.Measure"
final Class<Macro> macroClass = ( Class<Macro> ) Class.forName(
packageName + "." + macroName );
[javac] E:\com\mindprod\htmlmacros\LoadCodeToProcessMacro.java:130:
warning: [unchecked] uncheck
cast
[javac] found : java.lang.Class<capture#419 of ?>
[javac] required: java.lang.Class<com.mindprod.htmlmacros.Macro>
[javac] final Class<Macro> macroClass = ( Class<Macro> )
Class.forName( packageName
.." + macroName );
The other way of asking this is, what is the best practice in this
ugly situation?
warning messages? Where Macro is the name of an interface.
I understand the code is just using a plain Class object, and hence as
no idea if forName actually returned a Class object that implements
Macro. I am using the cast here is the C++ , "trust me" sense.
Ideally I would like the cast to fail if the class does not implement
Macro.
// e.g. "com.mindprod.htmlmacros.Measure"
final Class<Macro> macroClass = ( Class<Macro> ) Class.forName(
packageName + "." + macroName );
[javac] E:\com\mindprod\htmlmacros\LoadCodeToProcessMacro.java:130:
warning: [unchecked] uncheck
cast
[javac] found : java.lang.Class<capture#419 of ?>
[javac] required: java.lang.Class<com.mindprod.htmlmacros.Macro>
[javac] final Class<Macro> macroClass = ( Class<Macro> )
Class.forName( packageName
.." + macroName );
The other way of asking this is, what is the best practice in this
ugly situation?