public class TypeFactory { public static Type craeteType(SomeType param){ Type t = new Type(); if(param!=null) t.setParam(param); } }
Type type = new Type(); type.setId(jsonObj.optString("id")); type.setName(jsonObj.optString("name"));
public Type( String name ) { this.name = name; } public static Type booleanType = new BooleanType(); public static Type integerType = new IntegerType(); public static Type charType = new CharType(); public static Type undefinedType = new UndefinedType(); @Override public String toString() { return name; } private String name;
void onCreate(){ Type t = new subType(); t.setValue("whatever string you want"); Intermediate.setIntermediate(t); }
Class<T> tClass = ...; Type myType = new getGenToken<List.class, tClass>()
@Override public ListProperty<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Type elementType = ((ParameterizedType) typeOfT).getActualTypeArguments()[0]; Type listType = new CustomParametrizedType(ObservableList.class, null, elementType); ObservableList<?> list = context.deserialize(json, listType); return new SimpleListProperty<>(list); }
Type t = new Type("c", "d", "e"); StringWriter sw = new StringWriter(); mapper.writeValue(sw, t); System.out.println(sw.toString());
package forum21674070; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Type.class); Type type = new Type(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(type, System.out); } }
File root = new File("./build/classes"); URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() }); Class<?> loadedClass = Class.forName("events.Source", true,classLoader); // JSON --> Java "Create the actual type" Type listType = new DefaultParameterizedType(ArrayList.class, loadedClass); Gson gson = new Gson(); ArrayList<loadedClass> resourcesList = gson.fromJson(jsonString, listType);
Type result = new UtilDateUserType();
package com.type; public class Main { public static void main(String[] args) { Type first = new FirstType(); Type second = new SecondType(); System.out.println(func(first).getTypeName()); System.out.println(func(first).getTypeName()); System.out.println(func(second).getTypeName()); } public static Type func(Type type) { if(type instanceof FirstType) { type.setTypeName("First"); } else { type.setTypeName("Second"); // something here } return type; } }
JSONObject jjobject = jsarray.getJSONObject(j); Type genre = new Type();
JSONObject jjobject = jsarray.getJSONObject(j); Type genre = new Type();
DemoInterface<Type> demo = new DemoInterface<>() { <V> void demoMethod(Collection<V> someValues, SomeType<V, Type> moreValues) { Type type = new Type(); foreach(V value: someValues) { Type subtype = moreValues.doSomething(value); type.concat(subtype); } System.out.printf("result: %s%n", type); } }; SomeType<ValueA, Type> someA = new SomeType<>(); SomeType<ValueB, Type> someB = new SomeType<>(); List<ValueA> listA = new Arraylist<>(); // add some elements List<ValueB> listA = new Arraylist<>(); // add some elements demo.demoMethod(listA, someA); demo.demoMethod(listB, someB);