1

Does java have an equivalent operator or language construct as the verbatim operator(@) in C#?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Olaseni
  • 7,698
  • 16
  • 44
  • 68

2 Answers2

4

No, Java does not have such an operator.

Itay Maman
  • 30,277
  • 10
  • 88
  • 118
2

Quick Googling tells me that verbatim operator in C# is apparently just syntactic sugar.

No, there's no equivalent in Java. Java isn't about syntactic sugar, the main focus of Java as a language is to provide only one way to perform or otherwise get a single function, that's why each reserved word in Java has only one function and a lot of syntactic sugar is missing. Just to emphasise, @ is already reserved for annotations.

While the benefits and shortcomings of this can be discussed to eternity, the bottom line is that Java is really sparse in syntactic sugar, in fact only syntactic sugar in Java I can think of is the enhanced for loop and even then internally JVM knows only of while loops, anyway.

Esko
  • 29,022
  • 11
  • 55
  • 82
  • On a pedantic note, '+' is dual-purpose – Everyone Apr 06 '10 at 13:41
  • @Everyone: Indeed it is! – Esko Apr 06 '10 at 14:40
  • Quite a few of the reserved words have multiple functions. "this" comes to mind, as does "final". – Michael Borgwardt Apr 07 '10 at 10:56
  • @Michael: Care to elaborate, I can't think of functional differences to either of those. `final` basically prevents overriding/resetting value or method and `this` points to current instance of class (*or the enclosing superclass if the current class is anonymous*), what else? – Esko Apr 07 '10 at 11:04
  • preventing a class from being extended, a method from being overriden or a variable from being assigend to more than once are vaguely similar, but not at all the same thing. And "this" is also used in constructors to call different constructors - again, vaguely similar and certainly not bad language design, but technically quite different. – Michael Borgwardt Apr 07 '10 at 11:41