Java报错-静态方法不能直接调用非静态方法

1. 报错提示:

Cannot make a static reference to the non-static method quickSort(int[], int, int) from the type L912手撕快速排序Java(603979977)
void L912手撕快速排序.quickSort(int[] nums, int low, int high)

2. 报错原因

  1. quickSort 和 partition 不是静态方法
    你在 sortArray 里直接调用了 quickSort(nums, 0, nums.length - 1);,
    但 quickSort 和 partition 都是非静态方法,而 sortArray 是静态方法,
    静态方法不能直接调用非静态方法

  2. 解决方法:
    要么把 quickSort 和 partition 都改成 static,
    要么把 sortArray 也改成非静态方法,或者用对象调用。

posted @ 2025-07-19 21:06  kuki'  阅读(11)  评论(0)    收藏  举报