Replace new-like function call with 'new()'
Syntax update: replace new-like helper functions with new()
Reports calls to "new-like" helper functions that can be replaced with Go 1.26's new(expr) syntax.
A new-like function is a helper that takes a value and returns a pointer to a copy of that value. These functions are commonly used to create pointers to primitive values in struct initializations. Popular examples include proto.Int64, proto.String, proto.Bool, and similar functions from the Protocol Buffers library (google.golang.org/protobuf/proto).
Example:
Here, proto.String and proto.Int64 are new-like functions that create pointers to string and int64 values.
To simplify, use the Replace with 'new()' quick-fix. After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
GoReplaceNewLikeFunctionCall- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection ID: GoReplaceNewLikeFunctionCall
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |