CopyPastor

Detecting plagiarism made easy.

Score: 0.8870198471750707; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2014-05-03
by Akhil0181

Original Post

Original - Posted on 2013-01-26
by mattg



            
Present in both answers; Present only in the new answer; Present only in the old answer;



You could have your library not use either one, but some interface that you define that has all of the functions you need. Then for the Android version, you implement the interface using a Bitmap object, and for the desktop version, you implement the interface with a BufferedImage. The caller that uses your library passes in the implementation of the interface that corresponds to the platform the caller is using, and your code doesn't ever have to worry about platform specific stuff.
Of course, whether or not this is worth the effort depends on how extensively the image objects are used in your library. If it's just a line or two of code that needs to read the image, it may not be worth the trouble, and the reflection methods given in other answers might be easier.
You could have your library not use either one, but some interface that you define that has all of the functions you need. Then for the Android version, you implement the interface using a Bitmap object, and for the desktop version, you implement the interface with a BufferedImage. The caller that uses your library passes in the implementation of the interface that corresponds to the platform the caller is using, and your code doesn't ever have to worry about platform specific stuff.
Of course, whether or not this is worth the effort depends on how extensively the image objects are used in your library. If it's just a line or two of code that needs to read the image, it may not be worth the trouble, and the reflection methods given in other answers might be easier.

        
Present in both answers; Present only in the new answer; Present only in the old answer;