从静态方法引用

时间:2016-04-13 09:28:30

标签: java reflection

用?

替换foo()的内容
class MethodIteration {
  public static void main(String[] args) {
    for (MyFuncInt m : new MyFuncInt[] { Class1::method, Class2::method })
      System.out.println(m.getClass().foo()); // want Class1, Class2 etc here
  }
}

很抱歉简洁。移动设备;)

我不认为它是所提问题的副本,因为我想在包含静态方法的类之外获取名称。如果我尝试m.getClass().getName()我得到" MethodIteration $$ Lambda $ 1:[someHash]"。

1 个答案:

答案 0 :(得分:0)

我怕你不能。对public function rules() { return [ ['captcha', 'captcha', 'captchaAction' => 'site/captcha-login',], ]; } echo Captcha::widget([ 'id' => 'register-captcha', 'name' => 'RegisterModel[captcha]', 'captchaAction' => '/site/captcha-register' ]); 的调用包含在一个实现public function rules() { return [ ['captcha', 'captcha', 'captchaAction' => 'site/captcha-register',], ]; } 的lambda闭包中,该闭包没有访问包装类的方法(它甚至不是lambda类的声明字段)。

我说你不​​能使用功能界面。你必须创建一个函子来传递对类的引用(或者只是一个带有类名的字符串),所以你可以在以后检索它:

'session' => [
     'class' => 'yii\web\DbSession',
 ],

然后实例化如:

I = imread('image.jpg');
figure, imshow(I)

background = imopen(I,strel('disk',15));

I2 = I - background;
figure, imshow(I2);

I3 = imadjust(rgb2gray(I2));
figure, imshow(I3);

level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
figure, imshow(bw)
相关问题