0

In the course of writing some throw-away code, I ran into a weird problem with static methods. I've defined a static method that's supposed to return a Double , but Java insists that it's returning some new type named after the function.

Static method:

public class Temperature {
    // ...
    public static double CtoF( double c ) { return c * 1.8 + 32; }
    // ...
}

Call, outside of Temperature :

double temp = Temperature.CtoF( celsius );

Results in:

incompatible types
found: Temperature.CtoF
required: double

Any ideas?

EDIT: Never mind, it was a silly mistake on my part; I forgot that

celsius
[icode]
 was not itself a 
[icode]
Double

. Replacing the call with

double temp = Temperature.CtoF( new Double( celsius ) );

fixed the problem.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by JamesCherrill
0

Maybe you have an out-of-date .class file for Temperature, or that file isn't in the classpath when you execute your other class?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.