Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bypass package private #226

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/com/github/blindpirate/extensions/Bridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.blindpirate.extensions;

public class Bridge {

public static Object newCaptureSystemOutputExtension() {
return new CaptureSystemOutputExtension();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用一个空格分隔非空白字符。

}
}
19 changes: 10 additions & 9 deletions src/main/java/com/github/hcsp/encapsulation/Main.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.github.hcsp.encapsulation;

import com.github.blindpirate.extensions.CaptureSystemOutputExtension;
import com.github.blindpirate.extensions.Bridge;

public class Main {
public static void main(String[] args) {
System.out.println(createCaptureSystemOutputExtension().getClass().getName());
public static Object main(String[] args) {
return new Bridge().newCaptureSystemOutputExtension();
}

public static Object createCaptureSystemOutputExtension() {
// 因为CaptureSystemOutputExtension是包级私有的,因此无法直接创建它
// https://github.com/blindpirate/junit5-capture-system-output-extension/blob/4ee3aa0a0d9b2610b482e4571ecc33828c60248a/src/main/java/com/github/blindpirate/extensions/CaptureSystemOutputExtension.java#L44
// 想办法绕过这个限制,创建一个这样的实例。提示:你可以创建一些别的类和别的方法,并不一定非要在这个类中完成这件事。祝你好运!
return new CaptureSystemOutputExtension();
}

// public static Object createCaptureSystemOutputExtension() {
// // 因为CaptureSystemOutputExtension是包级私有的,因此无法直接创建它
// // https://github.com/blindpirate/junit5-capture-system-output-extension/blob/4ee3aa0a0d9b2610b482e4571ecc33828c60248a/src/main/java/com/github/blindpirate/extensions/CaptureSystemOutputExtension.java#L44
// // 想办法绕过这个限制,创建一个这样的实例。提示:你可以创建一些别的类和别的方法,并不一定非要在这个类中完成这件事。祝你好运!
// return Bridge.newInstance();

}