• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange long behavior

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

}



}
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic