I want to make inner method with Fluent Programming (a.k.a. Chaining method)
class OuterSay {
String sentence = "";
public OuterSay sayHello() {
class OtherLanguage {
public OuterSay inEnglish() {
sentence = "Hello!";
return this; // Error :: "this" is not OtherLanguage.
}
// and there are lots of other language method like inGermany(), inJapanese() and so forth..
}
return this;
}
}
Recently, I used chaining pattern to code easier than before. Please look at above example.
I want to make inner method (inEnglish() in sayHello() ) because, IDE will help me what can I select (in Eclipse Autocomplete). In that example, IDE recommend me what language can I choose.
But the problem is that I cannot return 'OuterSay' class from inEnglish() method by using "return this" as I learn Chaining method. Of course I know it doesn't work because 'this' object is not OuterSay class but OtherLanguage class. But I don't know how to solve it.
What should I do to use inner method with Fluent Programming? I want to return 'this', which is OuterSay class, in inner method. Please help me.