Gosu Tutorial for Java Developers: Learn Guidewire's Language Fast
By GuidewireTraining.com faculty · Updated
Short answer: Gosu is the statically typed, object-oriented language used to customize Guidewire InsuranceSuite. It runs on the Java Virtual Machine and can call Java libraries, so Java developers pick it up quickly. The main differences are type inference with var, first-class properties, blocks (lambdas), enhancements that add methods to existing types, and a built-in query API.
Why Java developers learn Gosu fast
Gosu was designed to feel familiar to Java programmers. It compiles to JVM bytecode, uses classes and interfaces, and is statically typed, so the compiler catches type errors before your code runs. What it adds is less boilerplate. The examples below are simplified for learning; check exact APIs against the documentation for your InsuranceSuite release.
Variables and type inference
In Gosu you rarely write the type twice. Declare with var and the compiler infers it.
var name = "Asha" // String
var premium = 1250.00bd // BigDecimal (bd suffix)
var count : int = 0 // explicit type when you want one
| Java | Gosu |
|---|---|
String name = "Asha"; |
var name = "Asha" |
import java.util.List; |
uses java.util.List |
x instanceof Policy |
x typeis Policy |
(Policy) x |
x as Policy |
p != null ? p.getName() : null |
p?.Name |
Properties instead of getters and setters
Gosu treats properties as first-class. You read and write them like fields, and Gosu calls the getter or setter for you.
contact.EmailAddress1 = "asha@example.com" // calls the setter
print(policy.Account.AccountNumber) // calls the getters
You define your own with property get and property set in a class.
Null safety
The ?. operator returns null instead of throwing a NullPointerException, and ?: supplies a default.
var city = contact?.PrimaryAddress?.City ?: "Unknown"
Blocks (Gosu’s lambdas)
A block is an anonymous function, written with a backslash. Collection methods take blocks, which replaces most loops.
var vehicles = policyPeriod.PersonalAutoLine.Vehicles
var newCars = vehicles.where(\ v -> v.Year >= 2023)
var makes = vehicles.map(\ v -> v.Make).toSet()
var total = vehicles.sum(\ v -> v.CostNew)
Enhancements
An enhancement adds methods or properties to an existing type without subclassing it. This is how you extend Guidewire entities cleanly.
package acme.enhancements
enhancement PolicyPeriodEnhancement : entity.PolicyPeriod {
property get IsHighValue() : boolean {
return this.TotalPremiumRPT.Amount > 50000
}
}
After this, any Gosu code can write period.IsHighValue.
Querying the database
Guidewire code reads data through the Query API, which builds SQL for you and returns typed entities.
uses gw.api.database.Query
var q = Query.make(PolicyPeriod)
q.compare(PolicyPeriod#PolicyNumber, Equals, "PA-0001")
var period = q.select().FirstResult
Writing data with bundles
Changes are made inside a bundle, which commits them as one transaction.
gw.transaction.Transaction.runWithNewBundle(\ bundle -> {
var c = bundle.add(contact)
c.EmailAddress1 = "asha@example.com"
})
What to learn next
Once the syntax is comfortable, move on to the data model (entities and typelists), PCF screens and rules. Read What is Guidewire PolicyCenter? for the product side, then practise with the Guidewire interview questions. Our PolicyCenter Development course teaches Gosu hands-on from day one.
Frequently asked questions
Is Gosu hard to learn for a Java developer?
No. Gosu's syntax, types and object model are close to Java. Most Java developers can read Gosu in a few days and write it confidently within a few weeks of practice.
Can Gosu use Java libraries?
Yes. Gosu runs on the Java Virtual Machine and can import and call Java classes directly with the uses statement.
Where is Gosu used in Guidewire?
Gosu is used across PolicyCenter, ClaimCenter and BillingCenter for business rules, entity enhancements, PCF screen logic, plugins, integrations and batch processes.