-1

I have the following class in Java:

class Adresse4 {
    private String strasse;
    private String hausnummer;
    private int postleitzahl;
    private String ort;
    private long telefon;

    Adresse4(String strasse, String hausnummer, int postleitzahl, String ort, long telefon) {
        this.strasse = strasse;
        this.hausnummer = hausnummer;
        this.postleitzahl = postleitzahl;
        this.ort = ort;
        this.telefon = telefon;
    }
    Adresse4(Adresse4 ad) {
        this.strasse = ad.strasse;
        this.hausnummer = ad.hausnummer;
        this.postleitzahl = ad.postleitzahl;
        this.ort = ad.ort;
        this.telefon = ad.telefon;
    }
}

and creating an object from this class like this:

Adresse4 adTest = new Adresse4("Lothstraße", "22", 80999, Ort.Berlin, 09909999);

My IDE tells me that the integer number is too large where I have declared a long.

How can I fix this?

Savior
  • 3,225
  • 4
  • 24
  • 48
fatso88
  • 7
  • 6

1 Answers1

1

Numbers which start with a 0 are in octal. e.g. 012 is 10 in decimal.

The number 09 isn't valid because 9 is not an octal digit.

In short, phone numbers are not integers and they usually include formatting such as leading 0's or + for international. You are better off storing it as a String or a PhoneNumber type which wraps a String.

e.g. my phone number starts +44 75... and the + would be discarded as an integer.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130