Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyParcelable implements Parcelable {
- private int mData;
- public int describeContents() {
- return 0;
- }
- public void writeToParcel(Parcel out, int flags) {
- out.writeInt(mData);
- }
- public static final Parcelable.Creator<MyParcelable> CREATOR
- = new Parcelable.Creator<MyParcelable>() {
- public MyParcelable createFromParcel(Parcel in) {
- return new MyParcelable(in);
- }
- public MyParcelable[] newArray(int size) {
- return new MyParcelable[size];
- }
- };
- private MyParcelable(Parcel in) {
- mData = in.readInt();
- }
- }
- public class ShushContainer<T extends Parcelable> implements Parcelable
- public class ShushContainer<T extends Parcelable> implements Parcelable {
- Vector<T> items;
- String someField;
- @Override
- public int describeContents() {
- return 0;
- }
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(someField);
- dest.writeInt(items.size());
- for(int i=0;i<items.size();i++)
- items.get(i).writeToParcel(dest, flags);
- }
- public ShushContainer(Parcel in) {
- someField = in.readString();
- int size = in.readInt();
- for(int i=0;i<size;i++)
- //this does not work
- items.add(T.CREATOR.createFromParcel(in));
- }
- public static final Parcelable.Creator<ShushContainer> CREATOR = new Parcelable.Creator<ShushContainer>() {
- public ShushContainer createFromParcel(Parcel in) {
- return new ShushContainer(in);
- }
- public ShushContainer[] newArray(int size) {
- return new ShushContainer[size];
- }
- };
- }
- public class ShushContainer<T extends ShushContainer<T> & Parcelable>
- implements Parcelable
- class Sample<T extends Sample<T> & Serializable> implements Serializable {
- public static int CONST = 0;
- public void foo()
- {
- T.CONST = 5;
- }
- }
- public class Base {
- public static int count = 10;
- }
- public class Child extends Base {
- public static int count = 20;
- }
- class Sample<T extends Base> {
- T t = null;
- public void printCount() {
- System.out.println(T.count);
- }
- public Sample(T t) {
- this.t = t;
- }
- public static void main(String[] args) {
- Sample<Child> sample = new Sample<Child>(new Child());
- Sample<Base> sample1 = new Sample<Base>(new Base());
- sample.printCount();//Child value printed as 10
- sample1.printCount();//Same for parent value printed as 10
- }
- }
- class Sample<T extends Serializable> implements Serializable {
- public int abc = 0;
- public void foo() {
- }
- public static void main(String[] args) throws SecurityException, NoSuchFieldException {
- TypeToken<Sample<Integer>> token = new TypeToken<Sample<Integer>>() {
- };
- Class<?> t = token.getRawType();
- Field field = t.getDeclaredField("abc");
- field.setAccessible(true);
- System.out.println(field.getName());
- }
- }
Add Comment
Please, Sign In to add comment