Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Google Play Services Interacting with Your API Interacting with Retrofit

Jose Mena
PLUS
Jose Mena
Courses Plus Student 18,978 Points

How does the Api interface work?

He declares the Api interface, and then uses some methods from the retrofit library to obtain an instance of an object that must implement this interface.

That was a little confusing to me, since I did not the implementation of this interface anywhere. How does retrofit figure this out?

1 Answer

Seth Kroger
Seth Kroger
56,414 Points

There are two features of the Java language called Annotations and Reflection. Annotations are the @-tags. Reflection lets you examine a class's definition within Java code at runtime.

Retrofit defines a number of custom annotations like @GET and @POST. These don't just link methods in the interface to a specific REST route. You call RestAdatper.create(Api.class) Retrofit will search the class for those custom annotations, and use the annotated method definitions to build it's own implementation.

You can learn a bit more about this in the Java Annotations course

Jose Mena
Jose Mena
Courses Plus Student 18,978 Points

Awesome I started looking into the Java Annotations course, thank you very much for the help