Question About Type Safety

I was reading Robert C Martin's article here:

http://today.java.net/pub/a/today/2005/03/09/factory.html

and I had a question about this section:

<begin quote>

publicinterface DynamicListFactory{

List make(String listType);}

publicclass NormalDynamicListFactoryimplements DynamicListFactory{

public List make(String listType){

if (listType.equals("InsertionList"))

returnnew LinkedList();

elseif (listType.equals("IndexedAccessList"))

returnnew ArrayList();

else

returnnull;

}

}

Code like this ought to make your hackles rise. Code like this is not type safe! On the other hand, code like this eliminates unnecessary recompiles and redeployments for volatile factories. Which of these two is more important depends on the project, and is a matter of some debate.

<end quote>

Is this code not type safe because if you mistype the name it will return null and you'll get a runtime error?

Thanks,

John

[1799 byte] By [hotquietdaya] at [2007-11-27 1:54:33]
# 1
anyone?
hotquietdaya at 2007-7-12 1:26:23 > top of Java-index,Java Essentials,Java Programming...
# 2

I don't get it either. Returning null might be a bad thing, but apart from that I don't see why it isn't type-safe. Also earlier in the article he says

"For example, let's say that we want a new method in the factory named makeIterableList, which creates the type of list that can be iterated over the fastest. The change to the AbstractListFactory class implies that every class that uses AbstractListFactory must be recompiled and redeployed."

This is false as well.

DrClapa at 2007-7-12 1:26:23 > top of Java-index,Java Essentials,Java Programming...