Home Answers Viewqa Java-Beginners Type casting the returned value of a method.

 
 


Justin Calleja
Type casting the returned value of a method.
2 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners

Hi,

How do you type cast the returned value of a method so that you can avoid creating a temporary variable. Here's an example:

panel.getComponent(i).(OnOffButton)setState('0');

I know that the component returned by panel.getComponent(i) will be of type OnOffButton. I want to avoid:

OnOffButton btn = (OnOffButton) panel.getComponent(i); btn.setState('0');

Is there a way around this?

Thanks,

Justin

View Answers

November 15, 2010 at 5:26 AM


Hi,

You may try following code:

((OnOffButton) panel.getComponent(i); btn.setState('0')).setState('0');

Thanks


November 16, 2010 at 3:02 PM


Hi,

That doesn't work. (Also, i'm trying to avoid creating the btn variable in the first place).

Thanks









Related Pages:
Type casting the returned value of a method.
Type casting the returned value of a method.  Hi, How do you type cast the returned value of a method so that you can avoid creating a temporary... know that the component returned by panel.getComponent(i) will be of type
Type casting
Type casting  how to type cast a string value to byte array
type casting
type casting  int n=20; n=sizeof((char)(float)n); what is n value
type casting
type casting  <--bean class-->method calllist is of object type... List (object type) <Object> totalList(int pi){ try{ Query q...){ return null; } how to type cast object type to entity type
type casting - Java Beginners
type casting and conversion  I am beginner and my query is Importance of type casting and conversion  Hi friend,public class TypeCasting...;Value of b after conversion : " + b); //Convert from boolean to short. s
Java type casting
Java type casting  Can a Byte object be cast to a double value
type casting
type casting  what is type casting
type casting purpose
type casting purpose  what is type casting , could u explain with practical example
Java type casting
Java type casting  What is Downcasting
Java Type Casting - Java Beginners
Java Type Casting  what is object type casting? give some example with related
java type casting problem - Java Beginners
java type casting problem  what is type casting? what is the type of type casting? explain with example?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/TypeCasting.shtml
Casting (Type Conversion)
Casting (Type Conversion)      ... casting. In java one object reference can be type cast into another object reference. This casting may be of its own type or to one of its subclass or superclasss
PHP Type Juggling
a float value to a variable then it becomes float type and if we assign...;Value of temp is:".$temp." and data type is: ".gettype($temp... "Value of temp is:".$temp." and data type is: ".gettype
java method return type : - Java Beginners
java method return type :  i have one question regarding methods,,, if we create a method with return type as class name (public employee addemp(int,int))what should be its return type.....and if any know this pls explain
Java bigdecimal setScale method example
working is demonstrated. Method return type is a bigdecimal value therefore... value is numerically equal to the object value in which the method is invoked. Scale... the returned value is numerically equivalent to this.object value.  While running
Problem with Double type Value in Access Database - Java Beginners
Problem with Double type Value in Access Database  Hello sir I have store Double Type Value in MS Access Databse,but when I search Record then it Gives Round Figure Value related with Percentage and I want to Store and Retrieve
JDOM Attribute Example, How to convert value of attribute in different data type
JDOM Attribute Example, How to convert value of attribute in different data type In this tutorial, we will see how to retrieve the value...()  method of the org.jdom.Attribute class returns the text value
What is casting?
What is casting?   Hi, What is casting? thanks
Method in Java
the type of value returned from a method. It can be a  valid Java type.... Return type of a method can be a primitive type or an object or a void. If the return type is void it means the method does not returns a value. In the second part
method - Java Beginners
the method must return a value that is assignable to a variable of the declared returned type. The getPermissions method could not return, say, a String, because...method  Method Sir, I am confusing in this sentence and did
Type Conversion - Java Beginners
Type Conversion   Hai, rajanikanth, Please explain how to convert from integer value to a string value .In a database operation i want to convert...); Thanks Rajanikant   Hai man use String.valueof(int i) method
Data Provider or other service returned an E_FAIL status Error
Data Provider or other service returned an E_FAIL status Error... and got the error "Data Provider or other service returned an E_FAIL status... that there was a datetime field in the database whose default value was "
What is the return type of the main method?
What is the return type of the main method?  hi, What is the return type of the main method? thanks   Hi, In the java programming the Main() method doesn't return anything hence declared void. In Java, you need
Java BigDecimal floatValue method example
translates bigdecimal value in to float type value. Method throws ..., original bigdecimal value is also shown.  Syntax for using the method: public... Java BigDecimal floatValue method example  
Method is undefined for the type Object(org.apache.jasper.JasperException)
Method is undefined for the type Object(org.apache.jasper.JasperException) .../bap/editPracticeRevenuSplit.jsp Generated servlet error: The method getPracticeRevenueCode() is undefined for the type Object
Type conversion example
value, Class type) { // TODO Auto-generated method stub if(value==null...Type Conversion Example An example of type conversion is given below, which... on Submit button, Then the converted value display on the browser. At first make
Get Ascii Value
that will be their ascii value. Method charAt() of String class is used to select... Get Ascii Value       To print ascii value of a character this is the the simplest way
Determining the type of Character
. To determine the character type we have used some static method of Character...Determining the type of Character In this section, you will learn how to determine the type of a character. You can use the methods of Character class
Introduction to Type conversion in Struts
parameters value and converts into a object. An example of type conversion...Introduction to Type conversion in Struts Type conversion is a mechanism or a process in which data is converted into one object type to other object type
JavaScript getAttributeNode method
;/div> <input type="button" value="Get Attribute Node(ID)" onclick="getAttributeNodeID();"> <input type="button" value="Get Attribute Node(Align... JavaScript getAttributeNode method   
JavaScript getAdjacentText method
value is beforeBegin then the returned text would be the text immediately before... in the textElement and if position value is afterEnd then the returned text would... JavaScript getAdjacentText method   
Java Method Return Value
Java Method Return Value       Java  method Return Value return to the code when... the value within the body of method. The method declared void does not return any
Data Type: number
Data Type: number       This Example shows you how to use number data type in velocity. Methods...;writer): Merge method of the Template class is used here for merging 
Reading Value From console
Reading Value From console  In case of String data Type readLine method of DataInputStream class read complete line of the given string but the next method of Scanner class doesn't read the complete line of String. why
Reading Value From console
Reading Value From console  In case of String data Type readLine method of DataInputStream class read complete line of the given string but the next method of Scanner class doesn't read the complete line of String. why
Casting in java - Java Beginners
Casting in java   Hi, I want to know Casting in detail... is implicit casting and Explicit casting . Implicit casting : Ex - assign... Explicit casting : Ex - Assign superclass variable to subclass
how to write to file primitive type double
a writeDouble() method to write a double value in binary files. writeDouble() method first converts the argument to a long and then writes the converted value...how to write to file primitive type double  Hi, How to write
JavaScript getAttribute method
of this getAttribute() method. The flag value may be 0, 1 or 2  and it is optional...;   <input type="button" value=" Get id " onclick="getID();">   <input type="button" value=" Get alignment " onclick="getAlignment();">
Java bigdecimal negate method example
class negate method. Method returns the same copy of the bigdecimal value but with opposite nature, that the bigdecimal value possess previously. Returned bigdecimal value will be as per context settings defined.  In short method return
Java bigdecimal setScale example
is demonstrated. Method return type is a bigdecimal value therefore it generates only bigdecimal object values. The returned bigdecimal object value is numerically equal to the object value in which the method is invoked. In short
Java BigInteger max value
these are equal, any of them may be returned. Syntax of max() method of BigInteger class... Java BigInteger max value       We can use the max() method of the BigInteger class to get
Multiple Value initialization and retrieval by put and get method
that how firstly in program we putting the value of the preferences like int type ,Boolean type, and simple key value after that we are just using the get method... Multiple Value initialization and retrieval by put and get method
Java bigdecimal scaleByPowerOfTen example
method working is demonstrated. Method return type is a bigdecimal value therefore it generates only bigdecimal object values. The returned bigdecimal object value... to the power n. In short the returned value is equivalent to this * (Ten to the power n
inserting value - JSP-Servlet
; <p><input type="submit" value="Submit" name="B1"> <input type="reset" value="... the jsp inserting the value in the jsp after that i want these value inserted
Get Absolute Value
as argument. We can use abs() method for double, float, int, long type values... Get Absolute Value       Absolute value is the only value of a number regardless
JavaScript getUTCDay() method
JavaScript getUTCDay() method       In JavaScript the method getUTCDay() returns a number between 0-6... is the Date object that we required to call the getUTCDay() method. In the following
Identify Excel's cell data type
Identify Excel's cell data type In this section, you will learn how you can identify cell's data type and handle it appropriately using Apache POI. In Apache POI library, for fetching each type of data, there is separate
JavaScript bold method
()); } </script> <input id="mytext" type="text" value... JavaScript bold method       One of the method defined in the string to show bold string
one attribute of type int - Java Beginners
function that returns the next month as a value of type month. Test your...one attribute of type int  hi friends can anyone help me... attribute of type int to represent a month (1 for January, 2 for February, and so
Criteria: Greater To Equal criteria for Date type
; date type value to the given within the table. Here is the simple Example code...Criteria: Greater To Equal criteria for Date type In this Example, We...-in Criterion types method. In This example search the result according to Criterion

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.