1
Actions act = new Actions(driver);
act.keyDown(CharSequence key);

If I search online to find out what CharSequence is, I get all the information about the CharSequence interface. I can't understand what does a CharSequence interface has to do with CharSequence key used in Actions class?

Thanks

zara
  • 99
  • 1
  • 8
  • 1
    The Interface of CharSequence is the definition of the type. Actions.keyDown(CharSequence key) says that the parameter key is any variable of type CharSequence. – NomadMaker Jul 02 '20 at 18:51
  • So is ("Keys.SHIFT, Keys.UP...etc) considered CharBuffer, Segment, String, StringBuffer or StringBuilder? Thanks – zara Jul 02 '20 at 20:07
  • 1
    No idea. You should check the JavaDoc for Keys. – NomadMaker Jul 02 '20 at 21:44
  • 1
    The point is that _it doesn't matter what the implementation is_. That's why the API accepts a `CharSequence` and not a specific implementation. – Slaw Jul 03 '20 at 06:57

1 Answers1

1

Take a look at the JavaDocs for CharSequence: https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html

Under implementing classes, you will see

CharBuffer, Segment, String, StringBuffer, StringBuilder

So by defining Action as taking a CharSequence parameter, it means that you can use any of the CharSequence implementations above, or possibly create your own. It is a way to loosely couple classes / class dependencies and make code more reusable and durable.

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80