The issue here is with your Object Oriented design. What kind of method is "methodInVideoOrThing()"? If this is a method that all things (including video's) have in common then it belongs in Thing. If it is a video-specific method then it belongs in Video.
In the first case (method of Thing) you can just cast the value from JList to Thing and you're done:
Thing selectedThing = (Thing) dorm.getSelectedValue();
selectedThing.methodInThing();
In the second case (method of Video) you have the problem you described of having to distinguish between different categories of Things like Videos, Fruit and Clothing. What I think I would do in this case is create separate classes to handle each category and pass the Object to it based on its category, a simple example:
public interface Handler {
public Class getCategory();
public void handle(Thing item);
}
public class VideoHandler implements Handler {
public Class getCategory() {
return Video.class;
}
public void handle(Thing item) {
if (!item instanceof getCategory()) {
throw new IllegalArgumentException("Wrong category - can only handle Video");
}
Video video = (Video) item;
// do video-things
}
}
In your calling class you need to select the correct handler based on the category:
private void init() {
List<Handler> handlers = new ArrayList<Handler>();
handlers.add(new VideoHandler());
// add other handlers
}
public void someMethod(Jlist dorm) {
Object item = dorm.getSelectedValue();
for(Handler handler : handlers) {
if (item instanceof handler.getCategory()) {
// optionally catch IllegalArgumentException here
handler.handle(item);
}
}
}
This can be made a bit nicer, for example use an enum as Category instead of the class, use generics to type the Handler and extract any common behavior (like the typechecking) into an abstract class, but this is the gist of it.