编写java程序中遇到的一个安全警告

来源:百度知道 编辑:UC知道 时间:2024/05/24 18:54:25
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class MyCanvas extends Canvas implements ComponentListener{
private BufferedImage bi;
private Image im;
private int image_width;
private int image_height;

public void setImage(BufferedImage bi){
this.bi=bi;
this.zoom();
}
public void zoom(){
if(bi==null)
return;
int screen_width=this.getWidth();
int screen_height=this.getHeight();
double screen_proportion=1.0*screen_width/screen_height;
image_width=bi.getWidth();
image_height=bi.getHeight();
double image_proportion=1.0*image_width/image_height;
if(image_proportion>screen_proportion){
image_height=screen_height;
image_width=(int)(image_height/image_proportion);
}else{
image_width=screen_width;
image_height=(int)(image_width*image_proportion);
}
im=bi.getScaled

那是Eclipse提供这个提示功能给你吧.
你点它warning的icon两下Eclipse就会自动给定.
如果你不喜欢,可以把它关掉,
windows -> preferences -> compiler -> Error/Warnings
-> Potential Programming problems
将Serializable class without serialVersionUID的warning改成ignore.

其实如果你没有考虑到兼容性问题时,那就把它关掉吧.
其实有这个功能是好的.
只要任何类别实作了Serializable这个介面,
如果没有加入serialVersionUID,Eclipse都会给你warning提示,
这个serialVersionUID为了让该类别Serializable后兼容.

考虑一下,如果今天你的类Serialized存到硬碟里,
可是后来你却更改了类别的field(增加或减少或改名).
当你Deserialize时,就会出现Exception.这样就会做成不兼容性的问题.

但当serialVersionUID相同时,它就会将不一样的field以type的预设值Deserialize.
这个可以避开不兼容性的问题.

自於你说内存的问题,我觉得没差多少吧.

这个警告无所谓了,你要时觉得难看,就在开始加上这样一段就可以了:
/**
*
*/
private static final long serialVersionUID = 1L;

警告你管他干嘛,没关系,不影响你程序运行就可以了。

好像说的是连续的类不能声明一个静态的结果什么什么的 字面意思字面意思