Quantcast
Channel: Stefan Hendriks' Blog » java
Viewing all articles
Browse latest Browse all 11

What is wrong with this code #02

$
0
0

Given that the functionality of the method toGenericObject must be preserved; there is something obviously wrong in this code, can you find it?

If so, can you think of an easy solution?


public MyObject {

	private String myField;
	 
	... (imagine multiple fields) ...

	public GenericObject toGenericObject() {
		GenericObjectFactory genericObjectFactory = GenericObjectFactory.getInstance();
		GenericObject genericObject = genericObjectFactory.create("myObject");
		genericObject.setField("myField", myField);
		// imagine multiple lines using genericObject.setField("field", field)
		return genericObject;
	}

}


Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images