我刚刚写了一些具有以下结构的代码:
public void method(int x) {
//...
}
public void method(int x, String... things) {
//...
}
Run Code Online (Sandbox Code Playgroud)
我很惊讶这编译了,如果我调用的话
method(3);
Run Code Online (Sandbox Code Playgroud)
然后它会选择第一个.显然,这在某种意义上是自然选择的,但如果第一种方法不存在,这将是调用第二种方法的合理方式(使用空的varargs数组).所以它应该被认为是模糊的并产生编译时错误?
或者这被视为特例?
这样对待它似乎是错误的,因为这意味着添加新方法可能会破坏现有代码,这不是一个非常幸福的事态.
(Goodness只知道如果第一个被添加为包含第二个子类的子类的新方法,你最终会调用哪个...)
我有这个代码
var a = ["a","a"]
a.name = "a"
unique(a)
function unique(arr){
arr.filter(function(e){
console.log(this.name) // undefined
})
}
Run Code Online (Sandbox Code Playgroud)
结果是未定义的,我想知道在这种情况下'this'指的是什么,我该怎么做才能使'this.name'实际上打印一些东西而不是undefined?
我知道这是一个愚蠢的问题,但我想知道案例标签为什么不采用变量.代码是 -
public class Hello
{
public static void main(String[] args)
{
final int y=9;
int a=1,b=2,c=3;
switch(9)
{
case y:
{
System.out.println("Hello User");
break;
}
case a:
{
System.out.println("Hello World");
break;
}
case b:
{
System.out.println("Buff");
break;
}
default:
{
System.out.println("Yo bitch");
break;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然,我已初始化a,b和c,但它显示错误.为什么?
现在,我有一个带有x li元素的ul容器.
我的计划:
<ul>
<li>xxx</li>
<li>xxx</li>
<li>xxx</li>
<li>xxx</li>
<li>xxx</li>
<li>xxx</li>
</ul>
<div> It would be cool if I'm after the 3th li-element only per CSS! </div>
Run Code Online (Sandbox Code Playgroud)
可能的解决方案:li:nth-child(3)然后设置div绝对值?
谢谢!!
ADD:我的li-elements有最小高度:50px和最大高度100px(响应)
我想声明一些抽象方法(所以在继承自这个方法的类中需要实现)以适应我的情况,即:
我正在制作一个拼图求解器程序.到目前为止我有3个包:
games.puzzlesgames.puzzles.rivercrossinggames.puzzles.rivercrossing.wolfgoatcabbage我不想太具体,但在games.puzzles.rivercrossing包中我有两个代表银行和州的类:GenericBank和GenericState.
现在,他们定义一些行为,但也有一些方法,从这些继承的类必须有,想move()将一个元件与一家银行转移到另一或者isPermitted()和isFinal()检查的状态.
例如,在过去的包我有WolfGoatCabbageGame类,它必须有自己Bank和State班将从一般的人继承.这些特殊的Bank和State类必须实现我上面提到的方法,例如在Wolf,Goat和Cabbage游戏中,检查山羊和狼是否不在同一个银行等.
所以最初我将泛型类声明为abstract,并且这些方法也要实现abstract:
public abstract class GenericBank {
// more members ...
public abstract boolean move(Element element, GenericBank dst);
// more members...
}
public abstract class GenericState {
// more members...
public abstract boolean isPermitted(GenericBank bank);
public abstract boolean isFinal(GenericBank bank);
// more members...
}
Run Code Online (Sandbox Code Playgroud)
这看起来好像有效,直到我发现我必须实例化 …
我需要制作一个看起来像这样的三角形
*
**
***
****
*****
******
*******
Run Code Online (Sandbox Code Playgroud)
目前我有一个看起来像的工作
*
**
***
****
*****
******
*******
Run Code Online (Sandbox Code Playgroud)
使用循环:
public static void standard(int n)
{
for(int x = 1; x <= n; x++)
{
for(int c = 1; c <= x; c++)
{
System.out.print("*");
}
System.out.println();
}
}
Run Code Online (Sandbox Code Playgroud)
我如何开展这项工作
*
**
***
****
*****
******
*******
Run Code Online (Sandbox Code Playgroud)
这是我的尝试:
public static void backward(int n)
{
for(int x = 7; x <= n; x++)
{
for(int y = 1; y >= x; y--)
{
if …Run Code Online (Sandbox Code Playgroud) 我有这个代码
import java.io.*; import java.util.*;
import javax.xml.parsers.*; import org.xml.sax.InputSource;
class TeamPlayer {
private int pulse;
TeamPlayer() { pulse= -10; }
TeamPlayer(int v0) {pulse= v0 +5;}
public int m(int v) { return 31%3 ;}
public int get_pulse() { return 1* pulse;}
}
class GoalKeeper extends TeamPlayer {
GoalKeeper() { stress -=8; }
public static int stress=3;
public int m(int v) { return (v & 3) + 15; }
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解"&"的含义.它与"&&"不同吗?
因此,如标题所述,为什么允许使用java?
int x = 0;
x = +-+-+-+-+-+-+-4;
Run Code Online (Sandbox Code Playgroud)
它没有用,它允许很难发现错误.
我有:
0001-2015
如何将此字符串拆分为0001和2015?
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int posn=0;
String reader;
String CSV = ",";
//String data []= new String [6]; //creates an array
File books = new File("books.txt");
if (books.exists() && books.length() != 0);
{
System.out.println("the file is there");
try {
BufferedReader in = new BufferedReader(new FileReader(books));
reader = in.readLine();
while (reader != null);
{
data = reader.split(CSV); //doesn't get past here
System.out.println("test");
Names[posn].setALL(data[0], Integer.parseInt(data[2]), data[1], data[3], data[4], Integer.parseInt(data[5]));
jSlider2.setMinimum(0);
jSlider2.setMaximum(posn);
posn++;
reader = in.readLine();
}
} catch (java.io.IOException e) { …Run Code Online (Sandbox Code Playgroud) java ×7
javascript ×3
jquery ×2
split ×2
case ×1
css ×1
for-loop ×1
html ×1
inheritance ×1
javac ×1
loops ×1
oop ×1
overloading ×1
regex ×1