java - Passing a class constant in param -
i've little problem in java. think i'm not still awake.
i have 2 classes:
the first 1 use constants jar (example : highgui.cv_load_image_color). in second 1 user select in list constant want use.
so, second class call method of first one, "stringify" constant use in param.
but first 1 can't use string in param has real class constant.
i know, that's stupid problem, i'm pretty sure i'm missing obvious.
someone have idea deal that?
edit :
a piece of code more clarity :
in class2
class1.finder("c:aaa.jpg","highgui.cv_load_image_color");
in class1
public void finder(string path1, string constant){ mat object = highgui.imread(path1, highgui.cv_load_image_color); //i want use "constant" instead of highgui.cv_load_image_color }
this looks design problem. passing strings around, containing name of java constant, not idea. why don't create class, or enum, containing value of color , description:
public enum describedcolor { cv_load_image_color("cv load image color", "red"), ... private string description; private string color; private describedcolor(string description, string color) { this.description = description; this.color = color; } }
then in class1 :
public void finder(string path1, describedcolor describedcolor) { ... }
and in class2 :
class1.finder("c:aaa.jpg", describedcolor.cv_load_image_color);
and in list displayed user, need store describedcolor instances, , use description value displayed user.
this way, you're oo, type-safe, self-documenting, , don't need nasty reflection tricks.
Comments
Post a Comment