假设我有两个自定义类和一个方法如下:
class A {
public void think() {
// do stuff
}
}
class B {
public void think() {
// do other stuff
}
}
Class C {
public void processStuff(A thinker) {
thinker.think();
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法写processStuff()这样的东西(只是说明):
public void processStuff({A || B} thinker) {...}
Run Code Online (Sandbox Code Playgroud)
或者,换句话说,有没有办法用一个接受多个类型的参数编写一个方法,以避免processStuff()多次输入该方法?
首先,是的,这是一个错误封闭的问题的完全重复.
我和原始海报有完全相同的问题(就像他一样,除了他这个问题我还没找到其他人).
我一直在努力解决这个问题超过1个月,甚至不得不求助于使用bitbucket(工作正常),即使我在GitHub上有付费计划,所以请耐心等待.不,这与维护无关(目前在https://status.github.com/上一切正常,我仍然得到与Vulpo相同的错误).
我的用户名和密码都不包含特殊字符.
我也可以使用不同的计算机正常推送,所以是的,这必须与我的电脑有关.我正在运行Arch Linux,这是我的git config -l:
alias.s=status
user.name=Gustavo Machado
user.email=gdmachado@me.com
credential.helper=cache
color.ui=auto
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff.meta=yellow bold
color.diff.frag=magenta bold
color.diff.old=red bold
color.diff.new=green bold
color.status.added=yellow
color.status.changed=green
color.status.untracked=cyan
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/gdmachado/paradigmas-de-programacao.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
Run Code Online (Sandbox Code Playgroud)
启动一个新的git文件夹并只推送一个README文件工作正常,但是一旦我尝试推送我的文件,它只会挂起一段时间,然后返回一个错误:
-%- src/paradigmas-de-programacao ‹master?› » git push -u origin master
Username for 'https://github.com':
Password for 'https://gdmachado@github.com':
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), …Run Code Online (Sandbox Code Playgroud) 我试图获得从pthread返回值并捕获该值的概念,但我无法理解发生了什么,或者如何使其工作.我有这个简单的程序创建一个单独的线程,这个线程以int值100退出,然后我尝试用pthread_join捕获该值:
#include <stdio.h>
#include <pthread.h>
void *doStuff(void *param) {
int a = 100;
pthread_exit(a);
}
void main() {
pthread_t thread;
int a;
pthread_create(&thread, NULL, doStuff, NULL);
pthread_join(thread, &a);
printf("%d\n", a);
}
Run Code Online (Sandbox Code Playgroud)
它有效,但抛出一些警告:
./teste.c: In function ‘doStuff’:
./teste.c:7:2: warning: passing argument 1 of ‘pthread_exit’ makes pointer from integer without a cast [enabled by default]
In file included from ./teste.c:2:0:
/usr/include/pthread.h:241:13: note: expected ‘void *’ but argument is of type ‘int’
./teste.c: In function ‘main’:
./teste.c:17:2: warning: passing argument 2 of ‘pthread_join’ …Run Code Online (Sandbox Code Playgroud)