1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * Interned strings
19  */
20 public class Main {
main(String args[])21     public static void main(String args[]) {
22         String a, b;
23         final String foo = "foo";
24         final String bar = "bar";
25 
26         // Two interned strings should match.
27         a = foo.concat(bar).intern();
28         b = foo.concat(bar).intern();
29         if (a == b && foo != bar) {
30             System.out.println("good! " + a);
31         } else {
32             System.out.println("bad! " + a + " != " + b);
33         }
34 
35         // An interned string should match a string literal.
36         a = ("f" + foo.substring(1,3)).intern();
37         if (a == foo) {
38             System.out.println("good! " + a);
39         } else {
40             System.out.println("bad! " + a + " != " + b);
41         }
42 
43         // Check that a string literal in libcore equals one in the app.
44         a = (new java.nio.charset.IllegalCharsetNameException(null)).getMessage();
45         b = "null";
46         if (a == b) {
47             System.out.println("good! " + a);
48         } else {
49             System.out.println("bad! " + a + " != " + b);
50         }
51     }
52 }
53