• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

static class

 
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Add the following line,

MyOuter.Inner s= new MyOuter.Inner();
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anand Damodaran wrote:Hi,
Add the following line,

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



That was not real problem.

 
Don't touch me. And dont' touch this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic