Initialize final variable within constructor in another method

前端 未结 3 1239
心在旅途
心在旅途 2021-01-12 04:10

I have a problem which isn\'t really that big, but still gives me some thought as to how Java constructors and methods are used.

I have a constant representing a rad

3条回答
  •  梦毁少年i
    2021-01-12 04:59

    How about doing like this?

    public MyProblematicClass {
        public final int RADIUS;
        public MyProblematicClass(... variables ...) {
           RADIUS = this.setRadiuswithCriteria(criteria);
    }
    
    private int setRadiuswithCriteria(criteria crit) {
    if(... crit ...) {
        return n;
    }
    return 0;
    }
    

提交回复
热议问题