我在同一个目录中有 3 个脚本,请在下面找到 x.sh、y.sh 和 z.sh 的内容:-
x.sh :-
xData="DataOfX"
function xInit(){
echo "xInit : data of a >$xData<"
}
Run Code Online (Sandbox Code Playgroud)
y.sh :-
. x.sh
xInit
sh z.sh zInit
Run Code Online (Sandbox Code Playgroud)
z.sh :-
function zInit(){
echo "zInit of z"
xInit
}
$@
Run Code Online (Sandbox Code Playgroud)
执行
. y.sh
在同一目录中给出以下输出:-
xInit : data of a >DataOfX<
zInit of z
z.sh: line 3: xInit: command not found
Run Code Online (Sandbox Code Playgroud)
子 shell 进程如何访问在父 shell 中初始化的变量和函数?
以下接口和类已成功编译.问题在下面的输出中提到:
interface MyInterface{}
class MyClass implements MyInterface{}
class InterDoubt{
static MyInterface mi ;//= new MyClass() ;
public static void main(String[] args){
System.out.println("X") ;
try{
synchronized(mi){
try{
mi.wait(4000) ;
}
catch(InterruptedException ie){
System.out.println("Exception occured at main.") ;
}
}
}
catch(Exception e){
System.out.println("voilla, MyInterface is an interface,\n" +
"then why compiler allows compilation of\n" +
"mi.getClass(), mi.wait().\n" +
"Or how the methods of Object class are available in an interface."
);
}
System.out.println("Y") ;
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
X
voilla,MyInterface是一个界面,
那么为什么编译器允许编译
mi.getClass(),mi.wait(). …
以下是MainClass.java中列出的代码.
public class MainClass {
public static void main(String[] args) {
System.out.println("main started...");
Class c = MyClass.class ;
//this class variable seems to be public static.
//But, as it is clearly visible in the MyClass,
//no reference variable is declared.
//My problem is that from where this class variable
//came from.
//i also check out the Object.java file, but it also don't
//have any public static class variable of Class class
//like there is
//out (instance of PrintStream class) in …Run Code Online (Sandbox Code Playgroud) 在下面的程序中,循环迭代1000次,我使用FileWriter在文件中写入所有条目,但不幸的是程序最终只在文件中写入510(有时是415,有时是692,总是少于1000)条目,但循环迭代1000次.
import java.io.* ;
import java.util.*;
public class DemoWriter {
public static void main(String[] args) throws Exception {
List<String> receiverList = new ArrayList<String>() ;
receiverList.add("abc@gmail.com") ;
receiverList.add("pqr@ibibo.com") ;
receiverList.add("xyz@gmail.com") ;
FileWriter fw = new FileWriter("a.txt") ;
BufferedWriter bw = new BufferedWriter(fw) ;
int size = receiverList.size() ;
String str ;
int count = 0 ;
for(int i = 1 ; i <= 1000 ; ++i){
str = receiverList.get( (int) (Math.random() * size) ) + "\n" ;
bw.write(++count + ".> " …Run Code Online (Sandbox Code Playgroud)