@@ -348,33 +348,39 @@ public static void exampleSnippet(String projectId, String filePath) {
348
348
// Snippet content ...
349
349
}
350
350
```
351
+
351
352
### Method Structure
353
+
352
354
Method arguments should be limited to what is absolutely required for testing (ideally having at
353
355
most 4 arguments). In most cases, this is project specific information or the path to an external
354
356
file. For example, project specific information (such as ` projectId ` ) or a ` filePath ` for an
355
357
external file is acceptable, while an argument for the type of a file or a specific action is not.
356
-
358
+
357
359
Any declared function arguments should include a no-arg, main method with examples for how
358
360
the user can initialize the method arguments and call the entrypoint for the snippet. If the
359
361
values for these variables need to be replaced by the user, be explicit that
360
362
they are example values only.
361
363
362
- Snippet methods should specify a return type of ` void ` and avoid returning any value wherever
363
- possible. Instead, show the user how to interact with a returned object programmatically by printing
364
- some example attributes to the console.
364
+ Snippet methods should return data that can be used in the calling method to show the user how to
365
+ interact with a returned object programmatically.
366
+
365
367
``` java
366
368
public static void main(String [] args) {
367
369
// TODO(developer): Replace these variables before running the sample.
368
370
String projectId = " my-project-id" ;
369
371
String filePath = " path/to/image.png" ;
370
- inspectImageFile(projectId, filePath);
372
+ List<String > results = inspectImageFile(projectId, filePath);
373
+ for (String result : results) {
374
+ // process result ...
375
+ }
371
376
}
372
377
373
378
// This is an example snippet for showing best practices.
374
- public static void exampleSnippet(String projectId, String filePath) {
379
+ public static List< String > exampleSnippet(String projectId, String filePath) {
375
380
// Snippet content ...
376
381
}
377
382
```
383
+
378
384
### Exception Handling
379
385
Samples should include examples and details of how to catch and handle common ` Exceptions ` that are
380
386
the result of improper interactions with the client or service. Lower level exceptions that are
0 commit comments