Stay organized with collections
Save and categorize content based on your preferences.
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);
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-04-28 UTC."],[],[]]