I am working on my project where I need to check if a specific value is equal or not to a value on a dataset.
This is the function I'm creating:
public void setSingleLimit(String columnName, Object limit){
}
where columnName
is the column of my dataset I will be applying the function to and limit
is the value used in the equality condition check.
So basically, this function will take the limit
value and check if all the values in columnName
are equal or not that value.
However, I do not know before hand the type of the column. I can, however, get the data type of the column in the function.
dataset.first().get(columnName).getClass()
gives me the class of the values in a column (we can safely and securely assume all the values in a column will belong to the same class/data type)
I would like to cast the limit
object received in the function to the columns class type in order to be able to do a comparison.
I KNOW I can override the function so it can accept different values (int, long, Boolean, String, etc.) and that will certainly work. However, I want to create a single method for less complexity and for easy understanding to my end user. We can also securely assume that the user will enter a correct value on the function, meaning that if the column is a column of Strings, the user will NOT put a value that is not a String.
Any idea of how I can cast an object to a class that is not known before hand?
Thank you.