0

I am new to Java and learning about data types, and how to convert them to other data types using the helper classes.

The issue I am having is I am getting the following compilation error "cannot find symbol" however I don't think I should be. I Read this SO question which makes sense, and while it helped me understand the problem, it did not help me solve it.

It seems to throw an error based on the name of my variable. Shouldn't I be able to name my variable anything I want (almost anything).

My very simple code:

public class file {
    public static void main(String[] args) {
        double oldDub = 450.6d; //initial double value
        Double newDub = new Double(oldDub); //create instance of above value
        float floatValue = newDub.floatValue(); //create a new data type using instance above
        int intValue = newDub.intValue(); //this works
        int randomVar = newDub.randomVar(); //this doesn't work
    }
}
Community
  • 1
  • 1
Kervvv
  • 751
  • 4
  • 14
  • 27
  • 3
    Double class doesn't have method 'randomVar'. That is why you receive cannot find Symbol – Kamil Banaszczyk Feb 08 '17 at 17:32
  • @KamilBanaszczyk gotcha, that makes sense, I thought the variable name (on the left) was also supposed to be present (on the right), but on the right, I am retrieving a method. Thank you! – Kervvv Feb 08 '17 at 17:36
  • 1
    Yes, you can name **your** methods and variables almost anything, but you can't make up method names for core Java classes and expect them to work. – Hovercraft Full Of Eels Feb 08 '17 at 17:36
  • Thank you, this makes complete sense @HovercraftFullOfEels, I just wasn't sure the the proper list of method names were for the Java Helper class. – Kervvv Feb 08 '17 at 17:40
  • Book mark this: [The Java API](https://docs.oracle.com/javase/8/docs/api/) and then refer to it often. – Hovercraft Full Of Eels Feb 08 '17 at 17:41

0 Answers0