- Home
- Interview Questions
- DevOps
26.
What is ExpandoMeta Class In Groovy?
Through this class programmers can add properties, constructors, methods and operations in the task. It is a powerful option available in the Groovy. By default this class cannot be inherited and users need to call explicitly. The command for this is “ExpandoMetaClass.enableGlobally()”.
27.
What Are Limitations Of Groovy?
Groovy has some limitations. They are described below
- It can be slower than the other object-oriented programming languages.
- It might need memory more than that required by other languages.
- The start-up time of groovy requires improvement. It is not that frequent.
- For using groovy, you need to have enough knowledge of Java. Knowledge of Java is important because half of groovy is based on Java.
- It might take you some time to get used to the usual syntax and default typing.
- It consists of thin documentation.
28.
How To Declare String In Groovy?
In Groovy, the following steps are needed to declare a string.
- The string is closed with single and double qotes.
- It contains Groovy Expressions noted in ${}
- Square bracket syntax may be applied like charAt(i)
29.
What Are Power Assertions In Groovy?
Writing tests means formulating assumptions by using assertions. In Java this can be done by using the assert keyword. But Groovy comes with a powerful variant of assert also known as power assertion statement. Groovy’s power assert differs from the Java version in its output given the boolean expression validates to false : def x = 1 assert x == 2 // Output: // // Assertion failed: // assert x == 2 // | | // 1 false This section shows the std-err output The java.lang.AssertionError that is thrown whenever the assertion can not be validated successfully, contains an extended version of the original exception message. The power assertion output shows evaluation results from the outer to the inner expression. The power assertion statements true power unleashes in complex Boolean statements, or statements with collections or other toString -enabled classes: def x = [1,2,3,4,5] assert (x << 6) == [6,7,8,9,10] // Output: // // Assertion failed: // assert (x << 6) == [6,7,8,9,10] // | | | // | | false // | [1, 2, 3, 4, 5, 6] // [1, 2, 3, 4, 5, 6]
30.
Can We Use Design Patterns In Groovy?
Design patterns can also be used with Groovy. Here are important points
- Some patterns carry over directly (and can make use of normal Groovy syntax improvements for greater readability)
- Some patterns are no longer required because they are built right into the language or because Groovy supports a better way of achieving the intent of the pattern
- some patterns that have to be expressed at the design level in other languages can be implemented directly in Groovy (due to the way Groovy can blur the distinction between design and implementation)