TypeToken is a class in a Google-provided library (Gson) that parses Json data
Gson TypeToken constructs protect instead of public.
why the TypeToken construction in Gson is so weird?
Using Retrofit to customize convert you see gson and you see TypeToken
I’m curious to see a class that uses the protect modifier. I rarely come across a class that does this, so I’m not sure it works. I asked a question on the SegmentFault and received an answer one of which is the link above, which has a description.
There are also some of their own understanding after receiving the answer after putting forward this question.
- Why is it
protect
notpublic
? In order not to create objects directly, you have to subclass them. - Why not?
abstract
? I’m not sure if subclasses have to be created in order to be used in the same package and in the same class - What is forcing subclasses for? Subclasses are forced to be created so that the __ subclass specifies the type __ of the generic declared by the parent class
Object
), here is the first time I feeljava
Unfortunately, you can’t force generic annotation.
Related knowledge required: Java basics, Java generic erasure