试图理解代码的原因
$(document).ready(function(){
// The below code is for evaluation quiz slider
var slideIndex = 1;
window.plusSlides = function(n) {
showSlides(slideIndex += n);
}
window.currentSlide = function(n) {
$('.next-slide').attr('data-index', n);
showSlides(slideIndex = n);
}
window.showSlides = function(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "inline";
dots[slideIndex-1].className += " active";
}
showSlides(slideIndex);
// When next is clicked
$('.next-slide').click(function() {
var index = $(this).attr('data-index')
currentSlide(index);
console.log('ok');
});
});
编译没有错误,执行没有异常,我开始摆弄Object [] one = new Object [1] [9];
Object [] [] two = new Object [8] [5];
two = (Object [] []) one;
之类的单维对象数组引用。
我发现这种类型的引用可以容纳任何对象的n维数组
Object [] one
这是很违反直觉的,似乎应该会产生一个编译器错误,例如
生成的错误。Object [] one = new Object [1][4];
one = new Object [5][4][8];
one = new Integer [5][3];
我给自己的解释是,由于Integer [] i = new Integer[2][2];
incompatible types: Integer[][] cannot be converted to Integer[]
可以容纳任何对象,因此实际上它被分配了最外面的数组,该数组又包含可以被视为对象的数组。由于我不确定这是否正确,因此任何人都可以提供证据证明这是怎么回事吗?