java - The method is undefined for the type Class<capture#3-of ? extends Command> -
i have abstract class
package main; public abstract class command { protected final string key; public command(string key) { this.key = key; } public abstract void function(string[] args); public abstract void help(); }
but when try call method function(string[] args)
, albeit in confusing , overly complicated way, problems ensue.
class<? extends command> x = (class<? extends command>) class.forname( "main.commands$" + string.valueof(command.tochararray()[0]).touppercase() + command.substring(1).tolowercase() ); x.function(args);
gives me error the method function(string[]) undefined type class<capture#3-of ? extends command>
i alternatively tried following:
command x = (command) class.forname( "main.commands$" + string.valueof(command.tochararray([0]).touppercase() + command.substring(1).tolowercase() );
but gave me cannot cast class<capture#1-of ?> command
.
i apologize in advance poor naming.
the class.forname
returning class<?>
object, not command
. need create command using 1 of constructors in class<?>
object.
class<command> klass = (class<command>) class.forname( "main.commands " + string.valueof(command.tochararray([0]).touppercase() + command.substring(1).tolowercase() ); command x = klass.newinstance();
alternatively can use klass.getconstructor(...)
method
Comments
Post a Comment