samedi 17 août 2019

How to access static block variables outside of class in java

I was working on some code in which I need to access the variable "hs" present in the static block of one class from another. Note: Both the class are preset in different packages.

Code is as follow:

public class A{
    static {
        HashSet<String> hs = new HashSet<>();
    }
}

I Googled about it but nothing found anything helpful. Your help would be very appreciable.

EDIT: I am not allowed to make changes in this file still need to access it from the other file.

Why I need to do this cause I am doing unit testing by JUnit and there is nothing what this block is returning which I can put assertEquals() on. So the option I left with is to test the side-effects and this variable "hs" value is getting changed as a side-effect. That's why I need to access it from another file.

Aucun commentaire:

Enregistrer un commentaire