• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

static class  RSS feed

 
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If below syntax can work then what's problem with my program ?

Locale aLocale = new Locale.Builder().setLanguage("fr").setRegion("CA").build();


---------- Compile ----------
MyOuter.java:9: error: incompatible types
MyOuter obj=new MyOuter.MyInner();
^
required: MyOuter
found: MyInner
1 error

Output completed (0 sec consumed) - Normal Termination
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyOuter.MyInner is a completely different class to MyOuter, it just happens to be declared within it. It doesn't work for exactly the same reason as you can't assign a JButton to a String variable.
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then how is this syntax working ?
Locale aLocale = new Locale.Builder().setLanguage("fr").setRegion("CA").build();
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you're making further method calls. Most of the methods of a Locale.Builder object return the same Locale.Builder object - that's a common approach to allow the chaining together of calls like this. But the important bit of that line is the last call to build(). That call (see java.util.Locale.Builder#build()) returns a Locale object.

Writing that line out longhand would look like this:

 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.It works.

---------- Run ----------
Output completed (0 sec consumed) - Normal Termination
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Add the following line,

MyOuter.Inner s= new MyOuter.Inner();
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anand Damodaran wrote:Hi,
Add the following line,

MyOuter.Inner s= new MyOuter.Inner();



That was not real problem.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!