Computing.Net > Forums > Programming > Java-Cannot convert double to class

Java-Cannot convert double to class

Reply to Message Icon

Original Message
Name: Dado
Date: February 14, 2005 at 15:25:49 Pacific
Subject: Java-Cannot convert double to class
OS: WinXP
CPU/Ram: 1GB
Comment:

I created a method for adding complex numbers that should return a value of type NameOfaClass. I also have two instance variables declared of type double (real and imaginary). The method is called from another class.:
public NameOfaClass sum(NameOfaClass number)
{
NameOfaClass somevalue = number;
return (somevalue.real+this.real)+(somevalue.imaginary+this.imaginary);
}
I get an error however saying that a double type cannot be converted to NameOfaClass type. Can anyone suggest how I could calculate this and return a value of type NameOfaClass? Do I need to create a new object of type NameOfaClass and somehow return the desired value? Help is greatly appreciated!


Report Offensive Message For Removal

Response Number 1
Name: Dado
Date: February 14, 2005 at 18:29:42 Pacific
Subject: Java-Cannot convert double to class
Reply: (edit)

Already figured it out. I created a new object of the class and returned it directly.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Java-Cannot convert double to class

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software