Java convention for unknown return type method

时间:2017-06-19 13:59:00

标签: java generics methods coding-style

I'm working on a workflow engine that will help customers to define their workflow on our product.

In this workflow engine, i made a system of condition to go or not to the next step, but these conditions can be everything. Like comparing execution date of a task with a metadata value, or comparing a "status" with a predefined constant. Or again comparing a execution time of a task with another one.

Well all these elements will be defined in a Definition, there'll be a sourceDefinion and a targetDefinition.

I was thinking for implementation, to create a method that will return a value according to the definition. Then i could compare these 2 returned values. (comparators are lower,greater or equals)

I know that , the only types can be returned are "Number", "Date" and "String".

So i'm returning an Object and then checking the instance before to compare.

I was wondering if it'd be more clean to work only with String type, and checking if it can be cast to Number or format to Date?

Thanks

1 个答案:

答案 0 :(得分:1)

The better way to deal with this kind of situation is to declare several function that deal with every possibility. So one function will return a Date, another a String, etc. But when you don't know what will be the return type choose Object.