Skip to content

Commit

Permalink
improve recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jun 27, 2024
1 parent b3ab3cd commit 8a282b1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/recipes/java-explicit-casting.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ For instance, the `PageContext` class has two `setLocale` methods:
To ensure the correct method is called, it is better to use explicit casting. Here's the modified example:

```run
<cfscript>
cs = new component implementsJava="java.lang.CharSequence" {
variables.text = "en_us";
Expand All @@ -62,6 +63,7 @@ dump(obj);
// Use the CharSequence object
getPageContext().setLocale(obj);
</cfscript>
```

In this example, we first cast the component to `java.lang.CharSequence` (the base interface for `String`), then call `setLocale`. With this explicit casting, Lucee is able to link the correct method.

0 comments on commit 8a282b1

Please sign in to comment.