return
string() +
"import java.util.ArrayList;\n" +
+ "import java.util.AbstractMap;\n" +
"import java.util.HashMap;\n" +
"import java.util.HashSet;\n" +
"import com.facebook.thrift.*;\n\n";
if (extends.empty()) {
f_service_ <<
- indent() << "private static interface ProcessFunction {" << endl <<
+ indent() << "protected static interface ProcessFunction {" << endl <<
indent() << " public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException;" << endl <<
indent() << "}" << endl <<
endl;
* @param container Is the type going inside a container?
* @return Java type name, i.e. HashMap<Key,Value>
*/
-string t_java_generator::type_name(t_type* ttype, bool in_container) {
+string t_java_generator::type_name(t_type* ttype, bool in_container, bool in_init) {
// In Java typedefs are just resolved to their real type
while (ttype->is_typedef()) {
ttype = ((t_typedef*)ttype)->get_type();
return (in_container ? "Integer" : "int");
} else if (ttype->is_map()) {
t_map* tmap = (t_map*) ttype;
- return "HashMap<" +
+ string prefix;
+ if (in_init) {
+ prefix = "HashMap";
+ } else {
+ prefix = "AbstractMap";
+ }
+ return prefix + "<" +
type_name(tmap->get_key_type(), true) + "," +
type_name(tmap->get_val_type(), true) + ">";
} else if (ttype->is_set()) {
} else if (ttype->is_enum()) {
result += " = 0";
} else if (ttype->is_container()) {
- result += " = new " + type_name(ttype) + "()";
+ result += " = new " + type_name(ttype, false, true) + "()";
} else {
result += " = null";
}
std::string java_package();
std::string java_type_imports();
std::string java_thrift_imports();
- std::string type_name(t_type* ttype, bool in_container=false);
+ std::string type_name(t_type* ttype, bool in_container=false, bool in_init=false);
std::string base_type_name(t_base_type::t_base tbase, bool in_container=false);
std::string declare_field(t_field* tfield, bool init=false);
std::string function_signature(t_function* tfunction, std::string prefix="");