- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
In the main method I make a new object of the DotComClass and set locationOfShips array to 14 numbers. Then send those values as an argument over to the setter method (setLocations) in the other class (see below). My question is why does it allow that pass over without issue, since I set the max number of elements of the locations instance variable is 5?
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
DotComClass dotCom = new DotComClass();
int[] locationOfShips = {6,7,8,9,1,2,3,4,4,4,4,5,5,5};
dotCom.setLocations(locationOfShips);
}
}
public class DotComClass {
int [] locations = new int[5]; // is this not related to the locations in the setter?
public void setLocations (int[] locations){
this.locations= locations;
System.out.println(Arrays.toString(locations));
}
}
最佳答案
locations
字段是对数组的引用。
这指向对 5 个整数的新数组的引用。
int [] locations = new int[5]; // is this not related to the locations in the setter?
这将引用重新指向不同的数组。
this.locations= locations;
新数组有自己的大小。它不受引用先前指向的数组大小的限制。
关于java - 数组实例变量与setter方法摄入无关吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56798293/
假设我们要描述一个满足以下真值表的组合电路: a b | s0 s1 s2 s3 ----------------- 0 0 | 1 d d d 0 1 | 0 1 d d 1 0 |
.mainIDv { height:300px; width:400px; padding:5px; margin: 8px auto 8px auto; } .ImgDisp{
我的 iOS 应用程序遇到了一个恼人的问题。突然,当我启动带有 TableView 的 View Controller 时,出现以下错误: Unrecognized selector sent to
我有一个简单的 PreferenceActivity 类,它的 onCreate 将我的 R.xml.preferences 屏幕传递给 ((PreferenceActivity)super).add
在大学项目范围内,我应该实现数据库的聚合。 我得到了一个实体关系模型,它看起来与此类似: 现在我应该实现一个 SQL 脚本来创建这样的数据库,但我在谷歌或其他任何地方找不到有关此主题的任何内容。在我教
我一直在努力阅读 GCD 并试图弄明白。我读了很多地方,应该始终使用 GCD,如果一个人正在做一些繁重的工作,这会卡住 UI,我确实理解这一点,但是 GCD 也可以仅仅为了性能而使用吗?假设我有一个循
当有人用他们自己的类重载线程时,这个问题似乎已经以一种或另一种形式得到了回答,但是如果只是尝试使用 QTimer 类而不扩展 QThread 类呢?我正在尝试将 QTimer 用于 QT。他们在 上的
在网上看了类似的问题/错误,没有一个对我有帮助... 未处理的拒绝 SequelizeEagerLoadingError:任务未关联到用户! 我的用户路线 router.get('', functio
如果我正在评估两个变量而不是两个方法调用,那么我使用“&&”或“&”是否重要 //some logic that sets bool values boolean X = true; boolean
我们目前正在内部为我们的项目使用 Oracle 10g,这不太可能改变,但最终我们将向其他客户提供此应用程序,我们需要能够提出替代的免费数据库。 那么使 Hibernate 持久层独立于所使用的底层
我的 AsyncTask 类中的 onPostExecute() 方法有问题。 我有一个SignupActivity: public class SignupActivity extends AppC
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我一直在大量关注 sequelize 的文档,但在处理关系时遇到了问题。这是我使用 belongsTo 创建两个非常基本的 1:1 关系的非常简单的代码 import Sequelize, { STR
我希望这与 GMT 无关,否则我会觉得自己很愚蠢。 2 个快速相关的问题。为什么这会转换为不同的日期?正在失去一天。我查看了其他答案中所述的时区,但它始终是 GMT 时区 0000,这正是我所期望的。
我发现了这个问题的很多版本,但似乎都没有比明显的 Google Chrome 错误更进一步。 发生的情况是,每当我将 codeigniter 设置复制到服务器上的新文件夹,以基于它启动新项目时,我在尝
我需要一个与 UI 无关的简单布局管理器。通过这个,我的意思是它不应该指定我想如何在屏幕上表示我的形状/控件。它应该能让我说: 我想要 X 形状。我想要 X 形下的 Y 形。我希望形状 Z 包围 X,
当有一个方法== , 方法 !=被定义为采用该结果并应用 !给它。 (可能还有 =~ 和 !~ 。) 与此不同,>= , 通常表示 >或 == , 实际上独立于 >和 == .这两个定义似乎都不会影响
我在 Ruby Netbeans 6.5.1 中获得了大量(我称之为)无关的自动完成信息。 例如,如果我输入一个模型对象的名称,然后输入一个句点(无论我是在 Controller 中还是在 View
我是 NodeJS 的新手,有 express 和 Sequelize。当我想创建图书租赁时,控制台会提示我“图书与租赁无关”。 当我将表迁移到 sql 数据库时,id 就在它们的位置并且我的播种机正
我有众所周知的错误: implicit declaration of function 'STLINKReadSytemCalls' [-Wimplicit-function-declaration]
我是一名优秀的程序员,十分优秀!