Q:

Java create dynamic class

I have 2 questions that I was hoping someone could help me with. Is there a way to create a class on the fly with android/java and also add variables to the class? For example I would like to do something like this:
Class c = new Class();
c.name = 'testing';
c.count = 0;

c.getName = new function(){
  return c.name;
}

Just wondering if this is possible or if there is another way to do this. Basically I want to build an object that I can use the data from as an object.

A:

No, the syntax you describe is not possible in Java.  I'm not sure what you are trying to accomplish there.  If you want to create a class to use to hold data on the fly, you can create an anoynmous inner class.
Object object = new Object() {
  private String name = testing;
  private int count = 0;

  public String getName() {
    return name;
  }
}

In general, I wouldn't use this for a data objects though.  This functionality is typically used for anonymous implementations of interfaces to support callbacks, etc.

