I read that Java String and Image classes implements 'Flyweight Design' pattern. I know, how to test this for a String class. But, I could not find a way to check this for Image class. My idea is that I will upload an image say "dog.png" into two image objects and then will compare the two image objects ( as shown below). If both objects are equal, this indicates that Java implements 'Flyweight' pattern, otherwise vice-versa.
Image img1= new Image("dog.png");
Image img2= new Image ("dog.png);
System.out.println( img1== img2) // should print 1, however it prints 0
The issue is when I execute the "new" statement, Java creates a fresh copy of the object, and there is no "intern" method (like String Class) is available. Do you have any idea that how one may check that Java Image class uses "Flyweight" pattern