Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

long - int problem  RSS feed

 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am practicing collections but stuck on very fundamental thing .

i made a class person ,in which a a variable -contactnum is of int type.

when i initialize its object ,as Person p1=new Person("abc",12,1234567890);
It says error ,as int cant take such long values ,
Then if i change datatype & all related datatypes(in contructor/methods) to long ,even then it says same error :int is out of range.
so finally i had to crop the passed data f lesser value :like ("abc",12,1234567);

But in real life ,how would i make it handle long values .

My class person is ::

class Person{
String name ;
int age;
long contactno;
Person(String n ,int a ,long c)
{
name=n; age=a;contactno=c;
}
public String toString(){
return(name+" "+age+" yrs old with ,Can be reached at " + contactno);
}
}





Thnx a lot ,
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler needs to be told that large literals are of type long. To do this, append a L to the end:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!