Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to put several groovy classes in the same groovy file?

Tags:

groovy

You know and I know it is possible to do in Java, provided only one is public. But, is it possible to do so in Groovy ? And if so under which conditions ?

like image 576
Riduidel Avatar asked Sep 03 '11 09:09

Riduidel


People also ask

Can a Groovy class extend a Java class?

Yes, you may intermix Java and Groovy sources in a project and have source dependencies in either direction, including "extends" and "implements".

Can I use Java classes in Groovy?

Groovy scripts can use any Java classes. They can be compiled to Java bytecode (in . class files) that can be invoked from normal Java classes. The Groovy compiler, groovyc, compiles both Groovy scripts and Java source files, however some Java syntax (such as nested classes) is not supported yet.

How do you define a class on Groovy?

A Groovy class is a collection of data and the methods that operate on that data. Together, the data and methods of a class are used to represent some real world object from the problem domain. A class in Groovy declares the state (data) and the behavior of objects defined by that class.


1 Answers

public class A{
Integer a=2
}

public class B{
Integer b=3+new CB().cb
}

private class CB{
Integer cb=2
}

assert new A().a+new B().b==7

Yes you can put them all in one file and just use them as you want in you main task... or what do you mean by "which conditions" ?

like image 84
Booyeoo Avatar answered Oct 01 '22 18:10

Booyeoo