我是Java的新手.现在我正在研究equals和==以及重新定义equals和toString.
我想使用我已经重新定义的toString方法和从Object类继承的默认方法.
我没有使用那个超级修饰符来达到那个方法.
这仅用于教育目的.如果您要查看我的代码中的注释,我希望得到的更清楚.
你能帮帮我吗?
我的代码是:
public class EqualTest{
public static void main(String[] args){
Employee alice1 = new Employee("Alice Adams", 75000, 1987, 12, 15);
//System.out.super.println(alice1);
Employee alice2 = alice1;
//System.out.super.println(alice2);
Employee alice3 = new Employee("Alice Adams", 75000, 1987, 12, 15);
//System.out.super.println(alice3);
System.out.println("alice1==alice2: " + (alice1==alice2));
System.out.println("alice1 == alice3: " + (alice1==alice3));
System.out.println("alice1.equals(alice3): " + alice1.equals(alice3));
}
}
class Employee{
...
public String toString(){
return getClass().getName() + "[name = " + name +
", salary=" + salary + ", hireDay=" + …Run Code Online (Sandbox Code Playgroud) while True:
reply = input('Enter text')
if reply == 'stop': break
print(reply.upper())
Run Code Online (Sandbox Code Playgroud)
结果是:
Run Code Online (Sandbox Code Playgroud)Enter text:Traceback (most recent call last): File "C:\PythonProjects\5.py", line 2, in <module> reply = input('Enter text:') EOFError: EOF when reading a line [Finished in 0.2s with exit code 1]
它只在Sublime Text 2.我试过IDLE,试过命令行,一切都很完美.为什么Subleme会对我大喊大叫?
顺便说一句,也许你也可以解释我在这种情况下可能意味着什么.当然,我在文档中已经读过,如果从输入中读取EOF,则会引发相应的错误.我想模仿这种情况.仅输入键盘?如果是,我应该输入什么组合键才能获得EOF?
先感谢您.
我无法理解这种send方法.我知道它用于操作发电机.但语法在这里:generator.send(value).
我莫名其妙地无法理解为什么值应该成为当前yield表达式的结果.我准备了一个例子:
def gen():
for i in range(10):
X = yield i
if X == 'stop':
break
print("Inside the function " + str(X))
m = gen()
print("1 Outside the function " + str(next(m)) + '\n')
print("2 Outside the function " + str(next(m)) + '\n')
print("3 Outside the function " + str(next(m)) + '\n')
print("4 Outside the function " + str(next(m)) + '\n')
print('\n')
print("Outside the function " + str(m.send(None)) + '\n') # Start generator …Run Code Online (Sandbox Code Playgroud) 我的例子是:
>>> def f(a, b, c, d): print(a, b, c, d, sep = '&')
>>> f(1,2,3,4)
1&2&3&4
>>> f(*[1, 2, 3, 4])
1&2&3&4
Run Code Online (Sandbox Code Playgroud)
要彻底了解它,我想查阅有关'*'的文档.
你能建议我去哪儿看吗?
我们来看一下:
print([object, ...], *, sep=' ', end='\n', file=sys.stdout)
Run Code Online (Sandbox Code Playgroud)
http://docs.python.org/py3k/library/functions.html?highlight=print#print
我们怎么解释'*'呢?通常星号('*')表示众多对象.但在这里,这对我来说是一个谜.在两个逗号之间...我甚至害怕认为这可能是一个错字.
你能澄清一下为什么这样有效:
public abstract class AbstractClassCreationTest {
public void hello(){
System.out.println("I'm the abstract class' instance!");
}
public static void main(String[] args) {
AbstractClassCreationTest acct = new AbstractClassCreationTest(){};
acct.hello();
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这与我们可以找到的规范相矛盾:
如果尝试使用类实例创建表达式(第15.9节)创建抽象类的实例,则这是编译时错误.
我有两个向量.我需要从vector1中删除vector2中的内容.我使用Visual Studio 2010.
似乎有一种方法:http: //msdn.microsoft.com/en-us/library/system.windows.vector.subtract.aspx
但它不知何故不起作用,甚至没有代码示例.
你可以帮帮我吗?如果不存在标准方法,也许您可以建议如何通过循环组织它?先感谢您.
#include "stdafx.h";
#include <vector>;
#include <iostream>
using namespace std;
int main ()
{
vector<int> vector1;
vector<int> vector2;
for (int i = 0; i < 10; i++)
{
vector1.push_back (i);
}
for (int i = 0; i < 6; i++)
{
vector2.push_back (i);
}
myvector1 = Subtract(vector1, vector2);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 嗯,这是我能看到的:
select host, user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | me |
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | debian-sys-maint |
| localhost | root |
| ubuntu | |
| ubuntu | root |
+-----------+------------------+
Run Code Online (Sandbox Code Playgroud)
我以root身份登录,想要更改用户'我'的密码.
SET PASSWORD FOR 'me'@'%' = PASSWORD('letmein');
Query OK, 0 rows affected (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
好吧,我们看不到任何影响行.
至于尝试访问,结果如下:
Access denied for user 'me'@'localhost' (using password: YES)
michael@ubuntu:/var/www/cgi-bin$
Run Code Online (Sandbox Code Playgroud)
所以,它提到localhost,而不是%.
你能建议我如何更改'我'的密码并解释%是什么?
当我尝试运行服务器时:
postgres@ubuntu:~$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets postgres@ubuntu:~$
Run Code Online (Sandbox Code Playgroud)
然后我将用户改为自己:
postgres@ubuntu:~$ su - michael
michael@ubuntu:~$ sudo netstat -tulpn | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 959/postgres
Run Code Online (Sandbox Code Playgroud)
好吧,postgres似乎正在听端口,这似乎是问题所在.
让我们将pack更改为postgres并尝试终止此过程:
postgres@ubuntu:~$ kill `cat /usr/local/pgsql/data/postmaster.pid`
Run Code Online (Sandbox Code Playgroud)
反应是:
cat: /usr/local/pgsql/data/postmaster.pid: No such file or …Run Code Online (Sandbox Code Playgroud) 我可以使用每种语法从数组中读取数据:
int[] a = new int[100];
for (int i = 0; i < 100; i++){
a[i] = i;
}
for (int element : a){
System.out.println(element);
}
Run Code Online (Sandbox Code Playgroud)
但同样可以填充阵列.说,有i*2价值观?
我没有发明这样的方法,而是宁愿问你我是不是错了.