java - JOptionPane getValue method -
i started studying java in college. , in online test, allowed search, had doubt method getvalue available in class joptionpane. true method returns object of class string? if not, why? kind of object method returns? please answer me. thank you.
it depends on joptionpane , value put there selected. if program gives user choice between several strings
(choose: "dog", "cat"...) can expect string
when calling getvalue()
method.
but careful, getvalue()
returns object class
object
, not string
. object
the mother of classes, , joptionpane
can hold want (string, integer, images other joptionpanes...) method getvalue()
can't sure of kind of class returning. that's why returning object of class
object
.
if sure joptionpane contains string
use this:
string mystring = (string) myjoptionpane.getvalue();
if not 100% sure, test result first:
if( myjoptionpane.getvalue() instanceof string){ string mystring = (string) myjoptionpane.getvalue(); }
now if wondering why question got voted down: may want google questions first. first way in java docs. example here description of joptionpane.getvalue(). don't confused complex looking docs. give correct answer want know how methods , classes work.
Comments
Post a Comment