Skip to content

Commit 4e50ed4

Browse files
authored
Updated sample codes and also the ones on docs to follow the best practice for using Java String
1 parent 482d0b5 commit 4e50ed4

File tree

11 files changed

+38
-38
lines changed

11 files changed

+38
-38
lines changed

doc_source/java-context.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Handler implements RequestHandler<Map<String,String>, String>{
3333
public String handleRequest(Map<String,String> event, Context context)
3434
{
3535
LambdaLogger logger = context.getLogger();
36-
String response = new String("200 OK");
36+
String response = "200 OK";
3737
// log execution details
3838
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
3939
logger.log("CONTEXT: " + gson.toJson(context));
@@ -79,10 +79,10 @@ import [com\.amazonaws\.services\.lambda\.runtime\.LambdaLogger](https://github.
7979
public class TestContext implements Context{
8080
public TestContext() {}
8181
public String getAwsRequestId(){
82-
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
82+
return "495b12a8-xmpl-4eca-8168-160484189f99";
8383
}
8484
public String getLogGroupName(){
85-
return new String("/aws/lambda/my-function");
85+
return "/aws/lambda/my-function";
8686
}
8787
...
8888
public LambdaLogger getLogger(){

doc_source/java-handler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Handler implements RequestHandler<Map<String,String>, String>{
2020
public String handleRequest(Map<String,String> event, Context context)
2121
{
2222
LambdaLogger logger = context.getLogger();
23-
String response = new String("200 OK");
23+
String response = "200 OK";
2424
// log execution details
2525
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
2626
logger.log("CONTEXT: " + gson.toJson(context));

doc_source/java-logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Handler implements RequestHandler<Object, String>{
2929
public String handleRequest(Object event, Context context)
3030
{
3131
LambdaLogger logger = context.getLogger();
32-
String response = new String("SUCCESS");
32+
String response = "SUCCESS";
3333
// log execution details
3434
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
3535
logger.log("CONTEXT: " + gson.toJson(context));

sample-apps/blank-java/src/test/java/example/TestContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ public class TestContext implements Context{
99

1010
public TestContext() {}
1111
public String getAwsRequestId(){
12-
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
12+
return "495b12a8-xmpl-4eca-8168-160484189f99";
1313
}
1414
public String getLogGroupName(){
15-
return new String("/aws/lambda/my-function");
15+
return "/aws/lambda/my-function";
1616
}
1717
public String getLogStreamName(){
18-
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
18+
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
1919
}
2020
public String getFunctionName(){
21-
return new String("my-function");
21+
return "my-function";
2222
}
2323
public String getFunctionVersion(){
24-
return new String("$LATEST");
24+
return "$LATEST";
2525
}
2626
public String getInvokedFunctionArn(){
27-
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
27+
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
2828
}
2929
public CognitoIdentity getIdentity(){
3030
return null;

sample-apps/java-basic/src/test/java/example/TestContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ public class TestContext implements Context{
99

1010
public TestContext() {}
1111
public String getAwsRequestId(){
12-
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
12+
return "495b12a8-xmpl-4eca-8168-160484189f99";
1313
}
1414
public String getLogGroupName(){
15-
return new String("/aws/lambda/my-function");
15+
return "/aws/lambda/my-function";
1616
}
1717
public String getLogStreamName(){
18-
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
18+
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
1919
}
2020
public String getFunctionName(){
21-
return new String("my-function");
21+
return "my-function";
2222
}
2323
public String getFunctionVersion(){
24-
return new String("$LATEST");
24+
return "$LATEST";
2525
}
2626
public String getInvokedFunctionArn(){
27-
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
27+
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
2828
}
2929
public CognitoIdentity getIdentity(){
3030
return null;

sample-apps/java-events-v1sdk/src/main/java/example/Handler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Handler implements RequestHandler<S3Event, String>{
1919
@Override
2020
public String handleRequest(S3Event event, Context context)
2121
{
22-
String response = new String("200 OK");
22+
String response = "200 OK";
2323
S3EventNotificationRecord record = event.getRecords().get(0);
2424
String srcBucket = record.getS3().getBucket().getName();
2525
// Object key may have spaces or unicode non-ASCII characters.

sample-apps/java-events-v1sdk/src/main/java/example/HandlerDynamoDB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class HandlerDynamoDB implements RequestHandler<DynamodbEvent, String>{
1818
@Override
1919
public String handleRequest(DynamodbEvent event, Context context)
2020
{
21-
String response = new String("200 OK");
21+
String response = "200 OK";
2222
for (DynamodbStreamRecord record : event.getRecords()){
2323
logger.info(record.getEventID());
2424
logger.info(record.getEventName());

sample-apps/java-events-v1sdk/src/main/java/example/HandlerKinesis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class HandlerKinesis implements RequestHandler<KinesisEvent, String>{
1818
@Override
1919
public String handleRequest(KinesisEvent event, Context context)
2020
{
21-
String response = new String("200 OK");
21+
String response = "200 OK";
2222
for(KinesisEventRecord record : event.getRecords()) {
2323
logger.info(gson.toJson(record.getKinesis().getData()));
2424
}

sample-apps/java-events-v1sdk/src/test/java/example/TestContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ public class TestContext implements Context{
99

1010
public TestContext() {}
1111
public String getAwsRequestId(){
12-
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
12+
return "495b12a8-xmpl-4eca-8168-160484189f99";
1313
}
1414
public String getLogGroupName(){
15-
return new String("/aws/lambda/my-function");
15+
return "/aws/lambda/my-function";
1616
}
1717
public String getLogStreamName(){
18-
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
18+
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
1919
}
2020
public String getFunctionName(){
21-
return new String("my-function");
21+
return "my-function";
2222
}
2323
public String getFunctionVersion(){
24-
return new String("$LATEST");
24+
return "$LATEST";
2525
}
2626
public String getInvokedFunctionArn(){
27-
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
27+
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
2828
}
2929
public CognitoIdentity getIdentity(){
3030
return null;

sample-apps/java-events/src/test/java/example/TestContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ public class TestContext implements Context{
99

1010
public TestContext() {}
1111
public String getAwsRequestId(){
12-
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
12+
return "495b12a8-xmpl-4eca-8168-160484189f99";
1313
}
1414
public String getLogGroupName(){
15-
return new String("/aws/lambda/my-function");
15+
return "/aws/lambda/my-function";
1616
}
1717
public String getLogStreamName(){
18-
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
18+
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
1919
}
2020
public String getFunctionName(){
21-
return new String("my-function");
21+
return "my-function";
2222
}
2323
public String getFunctionVersion(){
24-
return new String("$LATEST");
24+
return "$LATEST";
2525
}
2626
public String getInvokedFunctionArn(){
27-
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
27+
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
2828
}
2929
public CognitoIdentity getIdentity(){
3030
return null;

sample-apps/s3-java/src/test/java/example/TestContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ public class TestContext implements Context{
99

1010
public TestContext() {}
1111
public String getAwsRequestId(){
12-
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
12+
return "495b12a8-xmpl-4eca-8168-160484189f99";
1313
}
1414
public String getLogGroupName(){
15-
return new String("/aws/lambda/my-function");
15+
return "/aws/lambda/my-function";
1616
}
1717
public String getLogStreamName(){
18-
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
18+
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
1919
}
2020
public String getFunctionName(){
21-
return new String("my-function");
21+
return "my-function";
2222
}
2323
public String getFunctionVersion(){
24-
return new String("$LATEST");
24+
return "$LATEST";
2525
}
2626
public String getInvokedFunctionArn(){
27-
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
27+
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
2828
}
2929
public CognitoIdentity getIdentity(){
3030
return null;

0 commit comments

Comments
 (0)