A compile time error won't be possible.
Yet consider this implementation :
public class Folder {
private final File folder;
public Folder(String path) {
this(new File(path));
}
public Folder(File folder) {
if (!folder.exists() || !folder.isDirectory()) {
throw new IllegalArgumentException();
}
this.folder = folder;
}
// add useful methods possibly delegating to contained File object ...
}
This effectively prevents making Folder objects that contain a non directory File. Also note that I've set the folder field private, so no other class can tamper with it.