Questions tagged [compile-static]

18 questions
27
votes
1 answer

Groovy - as vs (cast)

Is there any practical difference between the following two approaches to casting: result.count = (int) response['hits']['total'] vs result.count = response['hits']['total'] as int I'm using @CompileStatic and the compiler is wanting me to do the…
Kong
  • 8,792
  • 15
  • 68
  • 98
13
votes
2 answers

Should I use Groovy's @CompileStatic if I'm also using Java 7

I've read through the "What's new in Groovy 2.0" and I'm a bit confused about when to use @CompileStatic. The article mentions that the @CompileStatic annotation was added for developers who weren't able to take advantage of the invoke dynamic part…
Scott
  • 16,711
  • 14
  • 75
  • 120
4
votes
1 answer

Groovy 2.1.0 weird behaviour of switch-case-break statement with @CompileStatic

I'm novice groovy programmer, and I faced weird behaviour of switch-case-break statement with static compilation (@CompileStaticannotation). It seems that breaks are ignored. Is it a bug or I've missed something while reading…
3
votes
1 answer

Error when referencing an attribute of type Map inside a closure

In the following code segment, why does the compiler complain about the map attribute but not other types of attributes: import groovy.transform.CompileStatic @CompileStatic class TestMapInClosure { Map amap = [:] List alist = [] …
Basel Shishani
  • 7,735
  • 6
  • 50
  • 67
2
votes
1 answer

Chance for this hole in Groovy staic typing to be fixed

When I run the following Groovy snippet, it prints ",a,b,c" as expected: @CompileStatic public static void main(String[] args) { def inList = ["a", "b", "c"] def outList = inList.inject("", { a, b -> a + "," + b }) …
OlliP
  • 1,545
  • 11
  • 22
2
votes
0 answers

Calling a closure from another when using @CompileStatic

When implicit calling a closure from another closure under @CompileStatic, the caller somehow goes into a recursive loop. Can you spot an issue with the code, or is this an issue with Groovy: import…
Basel Shishani
  • 7,735
  • 6
  • 50
  • 67
2
votes
1 answer

Grails 2.5.0 static compilation, controllers and grails features

I am testing out Grails static compilation, specifically GrailsCompileStatic. The documentation is limited in explaining what Grails dynamic features aren't supported. My test Controller is very simple, but I'm running into problems…
Townsfolk
  • 1,282
  • 1
  • 9
  • 21
1
vote
1 answer

Constructor cannot be applied to '(T)' error when using @CompileStatic and generic class

I'm trying to 'mend' some other code that I've been upgrading. I've boiled it down to a simple example generic class and then the use of that class. First, I declared a generic parameterized class like so //generic class class WillsAgent { …
WILLIAM WOODMAN
  • 1,185
  • 5
  • 19
  • 36
1
vote
1 answer

Named parameters compilation fails with @CompileStatic - how to fix it?

This piece of code works perfectly in dynamically typed Groovy buildDirectory.traverse(type: FILES, nameFilter: ~/dependency-updates-report.xml/) { reports << it } but when adding @CompileStatic to the class it get an error, something along the…
helpermethod
  • 59,493
  • 71
  • 188
  • 276
1
vote
0 answers

Groovy @CompileStatic with bounded generics

The Groovy compiler doesn't seem to like this generic method. @CompileStatic class GroovyMain { enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE } enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,…
jaco0646
  • 15,303
  • 7
  • 59
  • 83
1
vote
1 answer

Groovy extension methods in statically compiled code

There are many ways how to define extension methods for existing types in Groovy, e.g. meta-class, categories, extension modules etc. I'd like to know, which of them are compatible with static compilation via @CompileStatic. I know that it is…
Werner Thumann
  • 465
  • 4
  • 15
1
vote
0 answers

Groovy static compilation fails for nested generics

Please check the sample JUnit class below: import groovy.transform.CompileStatic import org.apache.commons.lang3.tuple.Pair import org.junit.Test import java.util.function.Function @CompileStatic class GroovyFunctionTypeInferenceTest { @Test …
1
vote
1 answer

@CompileStatic: automatic type cast possible?

Is it possible that the below code can be compiled with @CompileStatic? import groovy.transform.CompileStatic @CompileStatic class CompileStaticTest { List numbers = [] void addWithCase(something) { switch (something) { …
0
votes
1 answer

Why does the Groovy @TypeChecked annotation catch me putting a String into an int variable but not the other way around?

I'm having trouble understanding Groovy types and type promotion. And the exact promises of Groovy's @TypeChecked annotation. -- Or maybe I'm having trouble understanding some Groovy design philosophy. I was playing around with the @TypeChecked…
StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
0
votes
1 answer

groovy: convert a list of interface implementation to a map with compileStatic

I am just a newer to groovy. @Service @CompileStatic @Slf4j class JourneyExecutionService { @Autowired List engineList; Map engineMap; void init(){ engineMap =…
shijie xu
  • 1,975
  • 21
  • 52
1
2