Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


Justin Calleja
Type casting the returned value of a method.
2 Answer(s)      3 years and 8 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


Advertisement
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 Tutorials/Questions & Answers:
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  what is type casting
Advertisements
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 purpose
type casting purpose  what is type casting , could u explain with practical example
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
Type casting in java
Type casting in java In this section you will learn about type casting in java. Type casting is to convert one type to another type. Java support two types of casting; primitive type and reference type casting. Reference type casting
Java type casting
Java type casting  Can a Byte object be cast to a double value
Java Type Casting - Java Beginners
Java Type Casting  what is object type casting? give some example with related
Java type casting
Java type casting  What is Downcasting
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
What is casting?
What is casting?   Hi, What is casting? thanks
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
The method buildServiceRegistry() is undefined for the type ServiceRegistryBuilder
The method buildServiceRegistry() is undefined for the type ServiceRegistryBuilder  Hi, How to solve the error "The method buildServiceRegistry() is undefined for the type ServiceRegistryBuilder" in Hibernate 4.3.1? I am using
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
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 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
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
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 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
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  
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
Remove a value with remove() method
Remove a value with remove() method     ... by a index value using the remove() method. Specify the index position from where... a particular position specified by a  index value. Here is an example
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 "
Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view.
Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown...;Exceptions Next    Given a particular method condition
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
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?  How to change the value of a variable... the value in jsp by using jstl method for eg:'<'c:set var="name1" value="Add User
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
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   
FTPClient : Get System Type
This section explain how to get system type by using method of FTPClient class in java
MySQL Boolean Value
MySQL Boolean Value       MySQl Boolean Value is used to display the Boolean type status of the field... Value'. To understand the example execute a query 'SHOW TABLE STATUS LIKE "
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
Conversion from int to String
an int type value to a String type. You will convert an int value ... value from console and convert this int value to String type data. The line int... = Integer.toString(myint) converts myint int value to mystring String type data. Code
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();">
PHP Type Hinting
a value into objects of a class or to an array. Type Hints only supports object and array type, other primitive types like int and string are not supported. Go...PHP Type Hinting Function: Type hinting is a special type of function which
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
method
method  can you tell me how to write an abstract method called ucapan() for B2 class class A2{ void hello(){ system.out.println("hello from A2"); }} class B2 extends A2{ void hello(){ system.out.println("hello from B2
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
Programming - max3() method
Java: Programming - max3() method Problem Write a method which has three double parameters and returns the largest value. Details Method only. Write only the method, not main program. No I/O. As usual, this method should do no I/O
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
Java bigdecimal toBigInteger example
of bigdecimal class toBigInteger  method. Method default return type is a biginteger..., method will return 201 as biginteger objects cannot hold double type values.  Method generates NumberFormatException, if it finds the bigdecimal value
Java bigdecimal scale example
is demonstrated. Method return type is int therefore it generates only integer value... and any positive bigdecimal  value , the method generated scale...; For any negative bigdecimal  object value the method generated scale
Java BigDecimal doubleValue example
;    Java bigdecimal class doubleValue() method translates bigdecimal value in to double type value. Method throws NumberFormatException..., original BigDecimal value is also shown  Syntax for using the method: public
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
Java bigdecimal toBigIntegerExact example
class toBigInteger  method. Method default return type is a biginteger class object value.  If the bigdecimal object value is 423.0, method...; Method generates NumberFormatException, if it finds the bigdecimal value other
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
 

 

 

DMCA.com