小编And*_*lov的帖子

使用"this"指针而不使用它有什么区别吗?

使用"this"指针是否在运行时向程序添加了另一个操作?

只是举个例子来更好地解释这个问题:

class C
{
public:
    void set_x(int val){ x = val; }
    void set_this_x(int val){ this->x = val; }

private:
    int x;
};
Run Code Online (Sandbox Code Playgroud)

在运行时,函数"C :: set_x()"执行的操作比"C :: set_this_x()"少1吗?

谢谢!:-)

c++ performance this

11
推荐指数
3
解决办法
2847
查看次数

JUnit测试继承不起作用

public abstract class GenericTests<T extends Number> {
  protected abstract T getT();      

  @Test public void test1() {
    getT();
  }
}

public class ConcreteTests1 extends GenericTests<Integer> { ... }
public class ConcreteTests2 extends GenericTests<Double> { ... }
Run Code Online (Sandbox Code Playgroud)

根本不执行任何测试,忽略这两个具体类.我如何使其工作?(我希望test1()两个要执行IntegerDouble).

我使用JUnit 4.8.1.

更新:似乎问题与maven-surefire-plugin有关,而不是JUnit本身.请参阅下面的答案.

java junit surefire maven

11
推荐指数
1
解决办法
6664
查看次数

Active Records vs. Repository - 优点和缺点?

使用ActiveRecord,您可以定义这样的类:

class Contact
{
  private String _name;
  public String Name
  {
    get { return _name; }
    set 
    { 
      if (value == String.IsNullOrWhiteSpace())
        throw new ArgumentException(...);
      else
        _name = value;
    }
  }

  public Boolean Validate() { ... /* check Name is unique in DB */  }

  public Boolean Save() { ... }

  public static List<Contact> Load() { ... }
}
Run Code Online (Sandbox Code Playgroud)

虽然这很简单,但我发现我的课程变得非常臃肿,伴随着大量的逻辑组合!

使用分层/域设计,您可以定义相同的类,如:

class Contact
{
    [Required(AllowEmptyStrings=false)]
    public String Name { get; set; }
}

class ContactService : IService
{
    public List<Contact> …
Run Code Online (Sandbox Code Playgroud)

activerecord design-patterns architectural-patterns

10
推荐指数
3
解决办法
7498
查看次数

适用于OpenID + OAuth +普通身份验证的ASP.NET MVC解决方案

是否有一个事实上的ASP.NET MVC 3+解决方案应该使用,以防他需要允许用户通过以下方式登录/注册:

  • OpenID的
  • OAuth的
  • 琐碎的注册/手动认证

我基本上寻找的是"会员API",适用于OpenID,OAuth和其他任何东西.主要特点是:

  • 角色支持(适用于ASP.NET MVC)
  • 结合多种身份验证方法,单个用户的能力(例如,有人先用"小巫见大巫注册"报名了,然后他想捆绑他的谷歌帐户,然后他的雅虎帐户,所以他应该能够与任何这3对auth)

谢谢!

openid authentication asp.net-mvc oauth registration

7
推荐指数
1
解决办法
3005
查看次数

在Java中同步2个线程更简单的方法?

我不确定在使用辅助线程执行某些代码之后,主线程中的某些代码将被执行.这是我得到的:

    final Object lock = new Object();
    final Thread t = new Thread(new Runnable() {
        public void run() {
            synchronized(lock) {
                System.out.println("qwerty");
                lock.notify();
            }
        }
    });

    synchronized(lock) {
        t.start();
        lock.wait();
    }

    System.out.println("absolutely sure, qwerty is above");
Run Code Online (Sandbox Code Playgroud)
  1. 这是正确的解决方案?
  2. 有什么更短的方法吗?

java multithreading synchronization

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

C++中的头文件和Java中的抽象类/接口实现是否一致是正确的吗?

我有点熟悉C++,我知道对于几乎每个头文件,我都必须创建源文件.

现在我正在研究java接口和实现,它看起来是一样的.首先,您只需在一个类中命名变量和方法,然后在其他类中定义它们.

这些东西在C++和Java中是基本相同还是相似?

c++ java implementation

6
推荐指数
2
解决办法
7547
查看次数

异步套接字读取:不能退出启动线程 - 该怎么办?

我有一个我异步读取的NetworkStream(使用async/await)

await Task<int>.Factory.FromAsync((cb, state) => stream.BeginRead(buffer, offset, readLen - offset), stream.EndRead, null);
Run Code Online (Sandbox Code Playgroud)

不幸的是,有时会发生io异常:"由于线程退出或应用程序请求,I/O操作已中止."

我相信我达到了Socke.EndReceive中记录的要求:http://msdn.microsoft.com/en-us/library/w7wtt64b.aspx.哪个州:

当该线程退出时,由给定线程启动的所有I/O都将被取消.如果线程在操作完成之前退出,则挂起的异步操作可能会失败.

由于异步方法在默认调度程序上运行,因此无法保证此要求.

有没有解决的办法?我是否需要启动专用线程来启动I/O?

最好的问候,德克

c# multithreading asynchronous threadpool task-parallel-library

6
推荐指数
1
解决办法
1033
查看次数

如何在Swing中缩放画布上图像的特定区域

我想缩放图像上的特定区域.这是由用户选择的.使用Swing在画布上显示图像.我已经在画布上完成了全图像缩放,但无法实现特定的区域缩放.请帮忙

java swing canvas image

6
推荐指数
1
解决办法
4416
查看次数

GWT列表编辑器绑定

public interface Person {
    String getName();
    void setName(String name);
    List<PersonFriend> getFriends();
}

public interface PersonFriend {
    String getName();
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为以下内容实现一个仅查看编辑器Person:

public class PersonViewEditor extends Composite implements Editor<Person> {
    private static PersonViewEditorUiBinder uiBinder = GWT.create(PersonViewEditorUiBinder.class);
    interface PersonViewEditorUiBinder extends UiBinder<Widget, PersonViewEditor> {}

    @UiField Label nameEditor;
    @UiField PersonFriendsViewEditor friendsEditor;

    @UiField FancyAnchor editAnchor;

    public PersonViewEditor(ClientFactory clientFactory) {
        initWidget(uiBinder.createAndBindUi(this));
        editAnchor.setPlace(
                clientFactory.getPlaceHistoryMapper(), 
                clientFactory.getPlaceController(), 
                new EditPersonPlace());
    }
}

public class PersonFriendsViewEditor extends Composite {
    private static PersonFriendsViewEditorUiBinder uiBinder = GWT.create(PersonFriendsViewEditorUiBinder.class);
    interface PersonFriendsViewEditorUiBinder extends UiBinder<Widget, PersonFriendsViewEditor> …
Run Code Online (Sandbox Code Playgroud)

java gwt gwt-editors

6
推荐指数
1
解决办法
3169
查看次数

在Angular JS中,如何将指令属性中的数据注入模板?

这是我的指示:

app.directive("helloWorld", function() {
  return {
    restrict: "E",
    scope: {
      name: "bind"
    },
    template: "<div>a {{name}} a</div>"
  };
});
Run Code Online (Sandbox Code Playgroud)

这是我如何使用它:

<hello-world name="John Smith"></hello-world>
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我希望这个页面是这样的:

<hello-world>
  <div>a John Smith a</div>
</hello-world>
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,name没有注入,实际结果是这样的:

<hello-world>
  <div>a {{name}} a</div>
</hello-world>
Run Code Online (Sandbox Code Playgroud)

我缺少什么?我正在使用Angular JS 1.0.2

javascript templates angularjs

6
推荐指数
1
解决办法
5871
查看次数