Downcast « cast « Java Data Type Q&A

Home
Java Data Type Q&A
1.bigdecimal
2.biginteger
3.bit
4.Boolean
5.byte
6.Calendar
7.cast
8.character
9.Date Time
10.Date Time Format
11.decimal
12.Development
13.double
14.enum
15.float
16.hexadecimal
17.Integer
18.Number
19.Number Format
20.primitive
21.SimpleDateFormat
22.string
23.StringBuffer
24.StringBuilder
25.StringTokenizer
26.substring
27.TimeZone
Java Data Type Q&A » cast » Downcast 

1. Downcasting in Java    stackoverflow.com

Upcasting is allowed in Java, however downcasting gives a compile error. The compile error can be removed by adding a cast but would anyway break at the runtime. In this case ...

2. Forced Downcasting in Java    stackoverflow.com

I want to force a downcast on a object what can't be down casted and was wondering what the right approach would be. The use case is that I have a list ...

3. Detect Object type then cast it accordingly?    stackoverflow.com

My method takes as input an Object. How do i determine it's type, then cast it accordingly? So for example: binarySearch( Object o ); Inside the binarySearch method, i need a way to ...

4. Why can't I downcast this object in Java?    stackoverflow.com

I have this method:

    private Message getMessage(DataInputStream in) throws IOException {
    CommandEnum caption = CommandEnum.valueOf(in.readUTF());
    BasicMessage inputMessage;
    if (caption.equals(CommandEnum.BEGIN) ...

5. Use Method by Real Type    stackoverflow.com

I learned that I can use the real type of a Object to define which Method is used, such like this:

[...]
Object foo = new String("hello");
[...]
bla(foo);

void bla(String x){
}
void bla(Integer x){
}
Now it should ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.