0

this is the problem I'm trying to solve.

TextView[] containers=new TextView[2];

and I am calling following mehtod.

compeletLogin(containers);

and following is the method declaration.

 private void compeletLogin(@Size(2) TextView[] containers) {
    mEditTextName.setVisibility(View.GONE);
    mEditTextPass.setVisibility(View.GONE);
    mButtonLogin.animate().translationY(200);
    mButtonLogin.setText(R.string.logout);
    mImageProfile.setVisibility(View.VISIBLE);
    mTextViewName.setVisibility(View.VISIBLE);
    mTextViewName.setText(name);
    for (TextView tv: containers){
        tv.setVisibility(View.GONE);
    }
}

but when I am increasing length of array it's not giving me any error!

ASF
  • 64
  • 11
Urvish rana
  • 601
  • 10
  • 24

2 Answers2

0

AFAIK @Size only works on collection or array of primitive datatypes like int, float, double, long and String.

It doesn't work for Objects like TextView

Sagar
  • 23,903
  • 4
  • 62
  • 62
  • it is not clearly said in the documentation. ` The @Size annotation checks the size of a collection or array, as well as the length of a string. The @Size annotation can be used to verify the following qualities:` – Urvish rana Jun 04 '18 at 04:45
  • @UrvishranaU yes. The document doesn't highlight it. I have tried it out and seems only works with primitive type collections. You can also try with primitive type and it will work as expected – Sagar Jun 04 '18 at 04:51
  • but when I'm passing a formal argument as any identifier it won't work. e.g `void dosomthing(@Size(2) int[] data){}` and i'm calling with `dosomthing(new int[3])` works fine but when i do this `int[] data=new int[3]` and then passing it to 'dosmthing(data)` won't show me any warning or error.! – Urvish rana Jun 04 '18 at 05:08
0

Try using @Size(max=2) in place of @Size(2)

Jantzilla
  • 638
  • 1
  • 7
  • 19