我一直在用java编程,最近我开始学习一些c ++.
在C++中,将setter params设置为const是常规的,为什么我们在java中看不到这一点?
我的意思是创建一个像这样的setter有任何缺点:
public void setObject(final Object o){ this.o=o; }
Run Code Online (Sandbox Code Playgroud)
VS
public void setObject(Object o){ this.o=o; }
Run Code Online (Sandbox Code Playgroud)
第一个应该强制Object param o在整个set函数中保持不变,不是吗?
编辑:
最后一个参数将强制执行此操作:
public void setName(String name){
name="Carlos";
this.name=name;
}
Run Code Online (Sandbox Code Playgroud)
用户将永远无法设置与"Carlos"不同的名称
可能重复:
Java程序如何使用.jar中的文件进行读写?
如何从JAR java编译的项目中写入.txt文件?
当我运行我的项目时,它不会给出错误,但它不会写入JAR文件中的.txt.
我使用以下方法制作JAR文件:
netbeans clean /build tool
Run Code Online (Sandbox Code Playgroud)
public class FileIO {
private File file;
private Scanner filescScanner, lineScanner;
private PrintWriter fileWriter;
private String[][] data;
public FileIO () {
data = new String[100][2];
}
public String[][] getLineScores(){
return this.loadHighscores(this.getClass().getResourceAsStream("LineHighscores.txt"));
}
public String[][] getTimeScores(){
return this.loadHighscores(this.getClass().getResourceAsStream("TimeHighscores.txt"));
}
public void setLineScores( String name,String lines ){
boolean found= false;
data = this.getLineScores();
for(int i = 0; i<data.length && !found ; i++){
if(data[i][0] == null || "Niemand".equals(data[i][0])){
data[i][0]=name;
data[i][1]=lines;
found=true; …Run Code Online (Sandbox Code Playgroud) 我创建了一个指针向量
vector<Person*> *personVec = new vector<Person*>();
Run Code Online (Sandbox Code Playgroud)
人包含:
getName();
getAge();
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用迭代器它不起作用..这是我如何使用它:
vector<Person>::iterator it;
for(it = personVec->begin() ;
it != personVec->end() ;
++it)
{
cout << it->getName() << endl;
}
Run Code Online (Sandbox Code Playgroud)
我尝试过,vector<Person*>::iterator it;但也没有运气.
谢谢.
我知道这是一个简单的问题,但我似乎无法找到解决方案。
我目前正在使用带有 1920x1080 分辨率图像的引导轮播。我希望图像保持不变,但高度被裁剪到 480 像素。笔记。NO SCALING....图像应该只是被切断,没有拉伸或缩放。
可以说这是我的 css 类:
.carousel-top-img{
height: 480px;// image scaled down to 853x480px
}
Run Code Online (Sandbox Code Playgroud)
.carousel-top-img{
max-height: 480px;// image stretched but 1920x480px met
width: 100%
}
Run Code Online (Sandbox Code Playgroud)