You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In class "Intro to Groovy", I saved my Person class from the console to the file Person.groovy. When I ran:
$ groovy Person.groovy
it threw the following exception:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/Users/tamara/Projects/groovy-stuff/Person.groovy: 1: Invalid duplicate class definition of class Person : The source /Users/tamara/Projects/groovy-stuff/Person.groovy contains at least two definitions of the class Person.
One of the classes is an explicit generated class using the class statement, the other is a class generated from the script body based on the file name. Solutions are to change the file name or to change the class name.
@ line 1, column 1.
class Person {
^
1 error
A bit of a puzzler. The "fix" is to make the filename not match the class name.
classPerson {
String first
String last
String company
StringtoString() {
"$first$last at $company".toString()
}
}
Person me =newPerson(first: "big", last: "deal")
println me.properties
me.company ="yolo"println me.properties
println me.toString()
The text was updated successfully, but these errors were encountered:
In class "Intro to Groovy", I saved my
Person
class from the console to the filePerson.groovy
. When I ran:it threw the following exception:
A bit of a puzzler. The "fix" is to make the filename not match the class name.
This is the code:
The text was updated successfully, but these errors were encountered: