• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange long behavior  RSS feed

 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to compile following program and it is giving me error

"general.java:8: '.class' expected
gg.takeit(new Hashmap(), long 18L); "

Can somebody tell me what is wrong in the below program?



class general
{
public static void main(String[] args)
{
System.out.println("Hello World! general");
general gg = new general ();
gg.takeit(new Hashmap(), long 18);
}


public void takeit( Hashmap dd , long ee)
{
System.out.println("long value is "+ee);

}



}
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I believe that there are two problems.

1) The word "long" is a syntax error. You could use "(long)" as a typecast but that is unecessary because you have used the "L" suffix on the number 18 which makes the number 18 a long, and because in this case the "L" suffix isn't neccessary -- but it doesn't hurt anything. The number "18" without the "L" is an int and would automatically be converted to a long in this case as it is passed as a parameter. I think that you would need to use the "L" suffix to make an integral constant a long type for numbers that exceed the range of int.

2) The class "HashMap" is spelled with a capital "M" and it does make a difference since Java is a case-sensitive language.

Kaydell
 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I tired with the modifications suggested , but the result is still the same

import java.util.*;
class general
{
public static void main(String[] args)
{
System.out.println("Hello World! general");
general gg = new general ();
gg.takeit(new HashMap(), long 18);
}
public void takeit( HashMap dd , long ee)
{
System.out.println("long value is "+ee);
}
}

---------- javac ----------
general.java:10: '.class' expected
gg.takeit(new HashMap(), long 18);
^
1 error



Can somebody please help?
 
Sheikh Sadiruddin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hrishikesh Ghatnekar:
[QB]Well I tired with the modifications suggested , but the result is still the same

gg.takeit(new HashMap(), long 18)
When You call a method you should not specify the type. Remove long (before 18)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!