GenericTypeIndicator

public abstract class GenericTypeIndicator extends Object

Due to the way that Java implements generics (type-erasure), it is necessary to use a slightly more complicated method to properly resolve types for generic collections at runtime. To solve this problem, Firebase Database accepts subclasses of this class in calls to getValue (getValue(GenericTypeIndicator), getValue(GenericTypeIndicator)) and returns a properly-typed generic collection.

As an example, you might do something like this to get a list of Message instances from a DataSnapshot:


     class Message {
         private String author;
         private String text;

         private Message() {}

         public Message(String author, String text) {
             this.author = author;
             this.text = text;
         }

         public String getAuthor() {
             return author;
         }

         public String getText() {
             return text;
         }
     }

     // Later ...

     GenericTypeIndicator<List<Message>> t = new GenericTypeIndicator<List<Message>>() {};
     List<Message> messages = snapshot.getValue(t);

 

Public Constructor Summary

Inherited Method Summary

Public Constructors

public GenericTypeIndicator ()

发送以下问题的反馈:

此网页
需要帮助?请访问我们的支持页面