code: @SuppressWarnings("unchecked")
      public static <T extends View> T findViewById(Activity context, int id) {
          T view = null;
          View genericView = context.findViewById(id);
          try {
              view = (T) (genericView);
          } catch (Exception ex) {
              String message = "Can't cast view (" + id + ") to a " + view.getClass() + ".  Is actually a " + genericView.getClass() + ".";
              Log.e("Caffeine", message);
              throw new ClassCastException(message);
          }
  
          return view;
      }
docs: Utility method to make getting a View via findViewById() more safe & simple.
  <p/>
  - Casts view to appropriate type based on expected return value
  - Handles & logs invalid casts
  
  @param context The current Context or Activity that this method is called from.
  @param id      R.id value for view.
  @return View object, cast to appropriate type based on expected return value.
  @throws ClassCastException if cast to the expected type breaks.