How can I implement one reference to two identical classes?
===

I have two classes with identical implementations but different names.  They are generated and I'm not able to modify them:

    public class Foo {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    }

    public class Bar {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    }

I need to populate these classes with data, and since they are identical would prefer to do it with a single class or reference, then cast to (or hopefully the solution is more elegant) the Foo or Bar as needed.  Conceptually:

    FooOrBar fob = ????;   
    fob.setName("XYZ");
     
    Foo f = fob.(???);
    Bar b = fob.(???);

I've looked into generics, but it appears that is for when you truly don't know what Class you will be operating on.  Is it possible for me to have some type of Class or reference that achieves this?