问题列表 - 第40183页

分叉后,全局变量是否共享?

考虑这个简单的代码:

 int myvar = 0;
 int main() {
     if (fork()>0) {
       myvar++;
     } else {
       // father do nothing
     }
 }
Run Code Online (Sandbox Code Playgroud)

当孩子增加myvar时,值是否与父亲共享(如pthread)?

c unix linux fork

40
推荐指数
4
解决办法
4万
查看次数

Java:如何在Java Reflection中使用非原始类型的constructor.newInstance()?

经过漫长的一天搜索,如果构造函数采用非原始参数,我仍然无法弄清楚如何从自制类中实现新对象.现在我开始怀疑这是否可行?!

Reflection文档中,就我所见,他们只讨论基本类型(如int,float,boolean等).我发现的所有其他信息/网站/研讨会/示例也只是考虑原始类型来查找构造函数并实例化一个新实例.

所以我想要做的是以下(细分场景):

假设我有一个名为MyStupidClass的类.另一个类(我们将其命名为MyUsingClass)将MyStupidClass对象作为构造函数中的参数.现在在我的主应用程序中,我希望能够加载MyUsingClass类并将构造函数中的对象实例化.

这是我到目前为止发现的"使用反射":

使用空构造函数:

//the MyUsingClass:
public class MyUsingClass {

   //the public (empty) constructor
   public MyUsingClass() {
      ...
   }
}
Run Code Online (Sandbox Code Playgroud)

在主应用程序中,我现在会做类似的事情:

//get the reflection of the MyUsingClass
Class<?> myUsingClassClass = Class.forName("MyUsingClass");
//get the constructor [I use getConstructor() instead of getConstructors(...) here as I know there is only one]
Constructor<?> myUsingClassConstr = myUsingClassClass.getConstructor();
//instanciate the object through the constructor
Object myInstance = myUsingClassConstr.newInstance(null);
Run Code Online (Sandbox Code Playgroud)

现在如果我在MyUsingClass中使用一些原始类型,它看起来像:

//the MyUsingClass:
public class MyUsingClass { …
Run Code Online (Sandbox Code Playgroud)

java reflection constructor

3
推荐指数
1
解决办法
7037
查看次数

如何捕获文本框上的关键事件?

如果我专注于文本框,我按Enter或Esc

如何抓住这个事件?

c# asp.net

2
推荐指数
1
解决办法
1743
查看次数

邮件实际上并没有通过我的日志发送它说是

Rails 2.3.5

这是在我当地的.

我有一个简单的模型/视图/控制器

#contact.rb

def deliver_contact
  ContactMailer.deliver_contact(self)
end

#contacts_controller

def create
  @contact = Contact.new(params[:contact])

  respond_to do |wants|
    if @contact.save
      @contact.deliver_contact
      #flash[:notice] = 'Contact was successfully created.'
      wants.html { redirect_to('/thanks') }
    else
      wants.html { render :action => "new" }
    end
  end
Run Code Online (Sandbox Code Playgroud)

日志说它出去了..我可以在我的控制台上做它,并说它出去了.但我的收件箱中实际上没有收到任何内容.我错过了什么?

更新

这是我的development.rb:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => '25',
  :domain => "website.com",
  :authentication => :login,
  :user_name => "snackmail@gmail.com",
  :password => "aged-cheese"
}
Run Code Online (Sandbox Code Playgroud)

创建日志

Processing ContactsController#create (for 127.0.0.1 at 2010-11-28 16:12:49) [POST] …
Run Code Online (Sandbox Code Playgroud)

email ruby-on-rails actionmailer

0
推荐指数
1
解决办法
3063
查看次数

简单的GUI Java计算器

我正在构建一个简单的GUI Java计算器.我有一个问题,找到一个包或找出一个方法来进行实际的计算.到目前为止,我已经认为当我进行数学运算时,文本框中的数字会保存在临时位置.

然后,当我点击"="按钮时,它会进行计算,但我不知道如何告诉它采取临时加上数学运算和第二个数字,并根据所选的数学运算点击进行计算,+, -, *, /

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class JavaCalculator extends JFrame {
    private JButton jbtNum1;
        private JButton jbtNum2;
        private JButton jbtNum3;
        private JButton jbtNum4;
        private JButton jbtNum5;
        private JButton jbtNum6;
        private JButton jbtNum7;
        private JButton jbtNum8;
        private JButton jbtNum9;
        private JButton jbtNum0;
    private JButton jbtEqual;
        private JButton jbtAdd;
        private JButton jbtSubtract;
        private JButton jbtMultiply;
        private JButton jbtDivide;
        private JButton jbtSolve;
        private JButton jbtClear;
        private double TEMP;
        private double SolveTEMP; …
Run Code Online (Sandbox Code Playgroud)

java user-interface calculator

2
推荐指数
1
解决办法
15万
查看次数

解析十进制并在右边过滤额外的0?

从XML文件中我收到格式的小数:

1.132000
6.000000
Run Code Online (Sandbox Code Playgroud)

目前我正在使用Decimal.Parse,如下所示:

decimal myDecimal = Decimal.Parse(node.Element("myElementName").Value, System.Globalization.CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

c# string decimal

15
推荐指数
2
解决办法
7123
查看次数

注销时bash如何处理作业?

据我所知,从书籍和bash手册中可以看出.当用户从bash注销时,如果用户未使用nohup或disown,则用户启动的所有后台作业将自动终止.但今天我测试了它:

  1. 登录到我的gnome桌面并访问gnome-terminal.
  2. 终端中有两个选项卡,其中一个我创建了一个名为test的新用户并以test身份登录

    su - test
    
    Run Code Online (Sandbox Code Playgroud)
  3. 开始写一个剧本.

    cat test.sh
    #!/bin/bash
    sleep 60
    printf "hello world!!"
    exit 0
    
    
    ./test.sh &
    
    Run Code Online (Sandbox Code Playgroud)
  4. 之后我退出测试并关闭了标签

  5. 在下一个选项卡中,我以root身份执行了ps aux,发现该作业仍在运行.

这是怎么回事?

linux bash nohup

17
推荐指数
2
解决办法
7972
查看次数

用 C++ 播放声音

我需要在 C++ 中播放声音。它应该兼容所有平台。

谢谢,

花哨的

c++ audio

0
推荐指数
2
解决办法
2538
查看次数

Google App Engine - 如何将对象返回给我的servlet?

有没有人知道如何发送一个对象,更具体的一个List,从数据库中的查询得到的结果,到我的servlet,这是另一个Java应用程序,而不是在Google App Engine中.


更新:我在GAE中的servlet工作正常,它序列化我的List<Video>结果:

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {

    String titulo = req.getParameter("titulo");
    String json = "";

    PersistenceManager pm = PMF.get().getPersistenceManager();
    Query query = pm.newQuery("select from "+Video.class.getName()+ " where titulo.startsWith('"+titulo+"')");
    List<Video> video = (List<Video>) pm.newQuery(query).execute();

    json = new Gson().toJson(video);
    System.out.println("SERIALIZED >> " + json);

    res.setContentType("application/json");
    res.setCharacterEncoding("UTF-8");
    res.getWriter().write(json);
}
Run Code Online (Sandbox Code Playgroud)

我的调用servlet有这个方法:

public void receberMetaDados(String titulo) throws IOException, Exception{
    InputStream input = new URL("http://localhost:8888/serve?titulo="+titulo).openStream();
    Reader reader = new InputStreamReader(input, "UTF-8");
    List<Video> results = new …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine jsp servlets

2
推荐指数
1
解决办法
4404
查看次数

返回临时引用

我知道返回临时引用是违法的,但这是我的问题:

const stringSet & Target::dirList( const dirType type ) const
{
    switch( type )
    {
        case SOURCE_DIR:
            return m_sourceDirs;
        case HEADER_DIR:
            return m_headerDirs;
        case RESOURCE_DIR:
            return m_resourceDirs;
        default:
            return stringSet(); // PROBLEM HERE!
    }
}
Run Code Online (Sandbox Code Playgroud)

前三个选项返回对stringSet数据成员的const引用.我应该怎么做默认情况?如果我把它留下来,编译器(GCC -Wall -Wextra -pedantic)抱怨并且我不想要它,因为这些选项倾向于以最奇怪的方式抓住我的床设计选择:)

谢谢!

c++ reference switch-statement

4
推荐指数
1
解决办法
1872
查看次数