• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can someone explain the implementation of the constructor for this code fragment...

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this code which is part of an AsyncTask, what actually implements the interface (AsyncResponse)? It seems to be instantiated(?) in the class constructor. Does this make an instance of it? It is used to return data to the UI.
I used this to make a weather app, but would like a better idea of what I am doing as I implemented this after a lot of reading up, but am still learning.
Does this line from the Class further below make an object (or instance of the interface?)


Here is the Async class:


The calling part from In the main UI:



 
Rancher
Posts: 4615
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an anonymous class.
You'll probably find a fetchData$1.class file wherever your class files end up, which is the compiled version of this class, or something similar.

By the way, fetchData should be FetchData.  I was originally going to post that it wasn't a constructor but a method, until I realised you'd given your class a non-standard name.
 
Russell Sher
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. So does the anonymous class implement the interface?
Also, you mean I should rather name it FetchData to agree with class naming conventions?
And FetchData then is the anonymous class?
Russell
 
Dave Tolls
Rancher
Posts: 4615
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FetchData would be your class.

The anonymous class has no name.

Yes, the anonymous class implements the interface.
The implementation of AsyncResponse is in lines 6-11 (the one method that has).
 
Russell Sher
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,  thanks for that
regards
Russell
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic