I have a method that takes in Object as its argument. 

```
public String toStr(Object o) {}

```

There are two factory methods that generate two different instances. 

```
A a = FactoryA.generate() 
B b = FactoryB.generate()

```

In my code, 

```
Object y;
If (x) {
    y = FactoryA.generate() 
} else {
    y = FactoryB.generate()
}
toStr(y)

```

Is there a way to define a common type for A and B so that I can pass that common type to toStr() instead of using Object because I want a more specific type instead of Object for type checking. If class A and B had methods or fields in common, I would have made a superclass C or an interface C, so that I can replace Object with C. But A and B don't have common methods or fields. What's the best way to define a common type for A and B for this case? Are empty interfaces or empty abstract classes best way to go?