java - Name object by string variable -
the idea current year system running in, name study record after year , therefore refer current year.
basically string variable , use name of object. have seen similar not accurate want , lack explanation looking for.
date = new date();c // current date string currentyearrecord = integer.tostring(now.getyear()); // set string variable use name object studyrecord currentyearrecord = new studyrecord(); // name object string year got previous line.
unfortunately, manipulating variable names @ runtime not possible in java language. kind of feature possible in dynamic languages, python or javascript.
in plain java, can use map achieve need:
map<string, studyrecord> records; // init map , fill when relevant studyrecord currentyearrecord = records.get(integer.tostring(now.getyear()))
if need feature, have @ groovy, dynamic language running on jvm close syntax java.
Comments
Post a Comment