When does the constructor of a Scala user-defined annotation class gets executed?In Scala, how do you define a local parameter in the primary constructor of a class?scala: How to get the class in its own constructorWhere does Scala look for implicits?Annotation with User Defined classUser defined and default constructor?Functions in a Scala constructor don't get calledHow to enforce scala macro annotation constraints on annotated classes?Initialization of a C++ Struct with a user defined constructorHow to define val inside class constructor in ScalaHow to get the extended classpath of a Scala-macro-annotated class or object, in the macro?
How to stabilise the bicycle seatpost and saddle when it is all the way up?
My research paper filed as a patent in China by my Chinese supervisor without me as inventor
Does an oscilloscope subtract voltages as phasors?
Uncovering the Accelerated Dragon opening
Do ibuprofen or paracetamol cause hearing loss?
A medieval fantasy adventurer lights a torch in a 100% pure oxygen room. What happens?
What would be the seasonal impact on the indoor climate of a giant dome habitation?
Can the UK veto its own extension request?
Seized engine due to being run without oil
How are chord ratios developed exactly?
How do I find an ADC circuit's bandwidth experimentally?
Is there a star over my head?
Is low emotional intelligence associated with right-wing and prejudiced attitudes?
Which ping implementation is Cygwin using?
How to help my 2.5-year-old daughter take her medicine when she refuses to?
Can I disable a battery powered device by reversing half of its batteries?
Can I toggle Do Not Disturb on/off on my Mac as easily as I can on my iPhone?
Why aren't tangent spaces simply defined as vector spaces with same dimension as the manifold?
Linear Programming with additional "if-then"/"Default to zero" constraints?
Why would "an mule" be used instead of "a mule"?
Job offer without any details but asking me to withdraw other applications - is it normal?
Is there a reliable way to hide/convey a message in vocal expressions (speech, song,...)
Do Milankovitch Cycles fully explain climate change?
Why did it become so much more expensive to start a university?
When does the constructor of a Scala user-defined annotation class gets executed?
In Scala, how do you define a local parameter in the primary constructor of a class?scala: How to get the class in its own constructorWhere does Scala look for implicits?Annotation with User Defined classUser defined and default constructor?Functions in a Scala constructor don't get calledHow to enforce scala macro annotation constraints on annotated classes?Initialization of a C++ Struct with a user defined constructorHow to define val inside class constructor in ScalaHow to get the extended classpath of a Scala-macro-annotated class or object, in the macro?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I defined a Scala class MyAnnotation, used to annotate certain classes within my program:
case class MyAnnotation() extends scala.annotation.StaticAnnotation
println("MyAnnotation initialized") // doesn't get printed
Which is used in the following way:
@MyAnnotation()
class MyClass()
...
However, when I instantiate the MyClass class, the constructor of MyAnnotation doesn't get executed. I.e., the println does not happen.
val x = new MyClass()
// nothing gets printed
Sumarized: is there any way to provide a constructor to a user-defined annotation class that gets executed when another class annotated with that annotation is instantiated?
scala constructor annotations
add a comment |
I defined a Scala class MyAnnotation, used to annotate certain classes within my program:
case class MyAnnotation() extends scala.annotation.StaticAnnotation
println("MyAnnotation initialized") // doesn't get printed
Which is used in the following way:
@MyAnnotation()
class MyClass()
...
However, when I instantiate the MyClass class, the constructor of MyAnnotation doesn't get executed. I.e., the println does not happen.
val x = new MyClass()
// nothing gets printed
Sumarized: is there any way to provide a constructor to a user-defined annotation class that gets executed when another class annotated with that annotation is instantiated?
scala constructor annotations
1
Answer is NO.
– talex
Mar 28 at 9:37
Technically, the answer is yes: make it a macro annotation (docs.scala-lang.org/overviews/macros/annotations.html) and transform the constructor(s) of the annotated class in the macro. Whether this is code you want to write and maintain, is your decision. I certainly don't, which is why this isn't an answer :)
– Alexey Romanov
Mar 28 at 17:45
add a comment |
I defined a Scala class MyAnnotation, used to annotate certain classes within my program:
case class MyAnnotation() extends scala.annotation.StaticAnnotation
println("MyAnnotation initialized") // doesn't get printed
Which is used in the following way:
@MyAnnotation()
class MyClass()
...
However, when I instantiate the MyClass class, the constructor of MyAnnotation doesn't get executed. I.e., the println does not happen.
val x = new MyClass()
// nothing gets printed
Sumarized: is there any way to provide a constructor to a user-defined annotation class that gets executed when another class annotated with that annotation is instantiated?
scala constructor annotations
I defined a Scala class MyAnnotation, used to annotate certain classes within my program:
case class MyAnnotation() extends scala.annotation.StaticAnnotation
println("MyAnnotation initialized") // doesn't get printed
Which is used in the following way:
@MyAnnotation()
class MyClass()
...
However, when I instantiate the MyClass class, the constructor of MyAnnotation doesn't get executed. I.e., the println does not happen.
val x = new MyClass()
// nothing gets printed
Sumarized: is there any way to provide a constructor to a user-defined annotation class that gets executed when another class annotated with that annotation is instantiated?
scala constructor annotations
scala constructor annotations
asked Mar 28 at 9:28
MaartenMaarten
956 bronze badges
956 bronze badges
1
Answer is NO.
– talex
Mar 28 at 9:37
Technically, the answer is yes: make it a macro annotation (docs.scala-lang.org/overviews/macros/annotations.html) and transform the constructor(s) of the annotated class in the macro. Whether this is code you want to write and maintain, is your decision. I certainly don't, which is why this isn't an answer :)
– Alexey Romanov
Mar 28 at 17:45
add a comment |
1
Answer is NO.
– talex
Mar 28 at 9:37
Technically, the answer is yes: make it a macro annotation (docs.scala-lang.org/overviews/macros/annotations.html) and transform the constructor(s) of the annotated class in the macro. Whether this is code you want to write and maintain, is your decision. I certainly don't, which is why this isn't an answer :)
– Alexey Romanov
Mar 28 at 17:45
1
1
Answer is NO.
– talex
Mar 28 at 9:37
Answer is NO.
– talex
Mar 28 at 9:37
Technically, the answer is yes: make it a macro annotation (docs.scala-lang.org/overviews/macros/annotations.html) and transform the constructor(s) of the annotated class in the macro. Whether this is code you want to write and maintain, is your decision. I certainly don't, which is why this isn't an answer :)
– Alexey Romanov
Mar 28 at 17:45
Technically, the answer is yes: make it a macro annotation (docs.scala-lang.org/overviews/macros/annotations.html) and transform the constructor(s) of the annotated class in the macro. Whether this is code you want to write and maintain, is your decision. I certainly don't, which is why this isn't an answer :)
– Alexey Romanov
Mar 28 at 17:45
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394127%2fwhen-does-the-constructor-of-a-scala-user-defined-annotation-class-gets-executed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394127%2fwhen-does-the-constructor-of-a-scala-user-defined-annotation-class-gets-executed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Answer is NO.
– talex
Mar 28 at 9:37
Technically, the answer is yes: make it a macro annotation (docs.scala-lang.org/overviews/macros/annotations.html) and transform the constructor(s) of the annotated class in the macro. Whether this is code you want to write and maintain, is your decision. I certainly don't, which is why this isn't an answer :)
– Alexey Romanov
Mar 28 at 17:45