user5621896 February 2016

Is there any way to make the input from a scanner into an interface?

I am trying to take the input from a user and make it into an interface. Is there any way for me to do that directly from the scanner input? I don't really know how else I would do it. Thanks for the help. My code is

Scanner sc = new Scanner(System.in);

SetInterface target = sc.nextLine();

Is there any way for me to make this string input equal to an interface?

Answers


Samurai February 2016

You can never directly equal a Scanner input with an Interface defined by you.


cricket_007 February 2016

Short answer. You can't assign a String to an interface ever.

interface SetInterface {
    void doSomething(String s);
}

SetInterface target = "";

Compile error

incompatible types: java.lang.String cannot be converted to SetInterface

Post Status

Asked in February 2016
Viewed 2,251 times
Voted 5
Answered 2 times

Search




Leave an answer