"standard Simple" Interfaces In Java?
So here in Java I've written a typical class, to send json to a rest server. (I'll include the whole class below for clarity.) So that's a file 'Fetcher.java' Now for the callback
Solution 1:
I feel bad answering my own question, but as there were no other answers this info may be helpful.
DaveNewton and Rowtang have supplied the exact answers here:
(Point 1) If you want a genuinely public interface, it goes in its own file. That's how Java works. There's no alternative.
(Point 2) Normally, use protected interface
and declare the interface inside the class. It can then be used throughout the app.
So...
publicclassFetcherextendsAsyncTask<Void, Void, String> {
protectedinterfaceFetcherInterface {
publicvoidfetcherDone(String result);
}
privateString urlTail;
privateJSONObject jsonToSend;
privateFetcherInterface callback;
Fetcher(String ut, JSONObject toSend, FetcherInterface cb) {
urlTail = ut;
jsonToSend = toSend;
callback = cb;
}
@OverrideprotectedStringdoInBackground(Void... params) {
....
(c# programmers would maybe call it "IFetcher".)
Post a Comment for ""standard Simple" Interfaces In Java?"